59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { MetadataRoute } from "next";
|
|
import { LOCALES, LOCALE_HTML_LANG, DEFAULT_LOCALE } from "@/i18n";
|
|
import { getAllSegmentSlugs } from "@/data/segments";
|
|
|
|
const SITE_URL = "https://myinfomate.be";
|
|
|
|
function alternates(buildPath: (locale: string) => string) {
|
|
const languages: Record<string, string> = {};
|
|
for (const l of LOCALES) {
|
|
languages[LOCALE_HTML_LANG[l]] = `${SITE_URL}${buildPath(l)}`;
|
|
}
|
|
languages["x-default"] = `${SITE_URL}${buildPath(DEFAULT_LOCALE)}`;
|
|
return languages;
|
|
}
|
|
|
|
export default function sitemap(): MetadataRoute.Sitemap {
|
|
const now = new Date();
|
|
const entries: MetadataRoute.Sitemap = [];
|
|
|
|
for (const lang of LOCALES) {
|
|
entries.push({
|
|
url: `${SITE_URL}/${lang}`,
|
|
lastModified: now,
|
|
changeFrequency: "monthly",
|
|
priority: lang === DEFAULT_LOCALE ? 1 : 0.9,
|
|
alternates: { languages: alternates((l) => `/${l}`) },
|
|
});
|
|
}
|
|
|
|
for (const slug of getAllSegmentSlugs()) {
|
|
for (const lang of LOCALES) {
|
|
entries.push({
|
|
url: `${SITE_URL}/${lang}/${slug}`,
|
|
lastModified: now,
|
|
changeFrequency: "monthly",
|
|
priority: 0.8,
|
|
alternates: { languages: alternates((l) => `/${l}/${slug}`) },
|
|
});
|
|
}
|
|
}
|
|
|
|
entries.push(
|
|
{
|
|
url: `${SITE_URL}/mentions-legales`,
|
|
lastModified: now,
|
|
changeFrequency: "yearly",
|
|
priority: 0.3,
|
|
},
|
|
{
|
|
url: `${SITE_URL}/confidentialite`,
|
|
lastModified: now,
|
|
changeFrequency: "yearly",
|
|
priority: 0.3,
|
|
}
|
|
);
|
|
|
|
return entries;
|
|
}
|