42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
|
|
import { MetadataRoute } from 'next';
|
||
|
|
import { locales, defaultLocale } from '@/lib/i18n';
|
||
|
|
|
||
|
|
export default function sitemap(): MetadataRoute.Sitemap {
|
||
|
|
const baseUrl = 'https://haoaws.com';
|
||
|
|
const pages = ['', 'about', 'products', 'news', 'support'];
|
||
|
|
|
||
|
|
const sitemap: MetadataRoute.Sitemap = [];
|
||
|
|
|
||
|
|
// Add pages for each locale
|
||
|
|
locales.forEach((locale) => {
|
||
|
|
pages.forEach((page) => {
|
||
|
|
const url =
|
||
|
|
locale === defaultLocale
|
||
|
|
? `${baseUrl}${page ? `/${page}` : ''}`
|
||
|
|
: `${baseUrl}/${locale}${page ? `/${page}` : ''}`;
|
||
|
|
|
||
|
|
sitemap.push({
|
||
|
|
url,
|
||
|
|
lastModified: new Date(),
|
||
|
|
changeFrequency: page === '' ? 'daily' : page === 'news' ? 'weekly' : 'monthly',
|
||
|
|
priority: page === '' ? 1 : page === 'products' ? 0.9 : 0.8,
|
||
|
|
alternates: {
|
||
|
|
languages: locales.reduce(
|
||
|
|
(acc, loc) => {
|
||
|
|
const altUrl =
|
||
|
|
loc === defaultLocale
|
||
|
|
? `${baseUrl}${page ? `/${page}` : ''}`
|
||
|
|
: `${baseUrl}/${loc}${page ? `/${page}` : ''}`;
|
||
|
|
acc[loc] = altUrl;
|
||
|
|
return acc;
|
||
|
|
},
|
||
|
|
{} as Record<string, string>,
|
||
|
|
),
|
||
|
|
},
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
return sitemap;
|
||
|
|
}
|