72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { config } from '@/lib/config';
|
|
import { MetadataRoute } from 'next';
|
|
|
|
import { getAllPostsMetadata } from '@/lib/blog';
|
|
import { getAllPagesMetadata } from '@/lib/pages';
|
|
import { mapFileSlugToTranslated } from '@/lib/slugs';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
|
const baseUrl = config.baseUrl || 'https://e-tib.com';
|
|
const locales = ['de', 'en'];
|
|
|
|
const sitemapEntries: MetadataRoute.Sitemap = [];
|
|
|
|
for (const locale of locales) {
|
|
// Helper to generate localized URL Segment
|
|
const getLocalizedRoute = async (pageKey: string) => {
|
|
if (pageKey === '') return '';
|
|
const translated = await mapFileSlugToTranslated(pageKey, locale);
|
|
return `/${translated}`;
|
|
};
|
|
|
|
// Static routes
|
|
const staticPages = ['', 'blog', 'kontakt', 'karriere', 'kompetenzen', 'ueber-uns'];
|
|
for (const page of staticPages) {
|
|
const localizedRoute = await getLocalizedRoute(page);
|
|
sitemapEntries.push({
|
|
url: `${baseUrl}/${locale}${localizedRoute}`,
|
|
lastModified: new Date(),
|
|
changeFrequency: page === '' ? 'daily' : 'weekly',
|
|
priority: page === '' ? 1 : 0.8,
|
|
});
|
|
}
|
|
|
|
|
|
|
|
// Blog posts
|
|
const translatedBlog = await mapFileSlugToTranslated('blog', locale);
|
|
const postsMetadata = await getAllPostsMetadata(locale);
|
|
for (const post of postsMetadata) {
|
|
if (!post.frontmatter || !post.slug) continue;
|
|
|
|
const translatedSlug = await mapFileSlugToTranslated(post.slug, locale);
|
|
|
|
sitemapEntries.push({
|
|
url: `${baseUrl}/${locale}/${translatedBlog}/${translatedSlug}`,
|
|
lastModified: new Date(post.frontmatter.date),
|
|
changeFrequency: 'monthly',
|
|
priority: 0.6,
|
|
});
|
|
}
|
|
|
|
// Static pages
|
|
const pagesMetadata = await getAllPagesMetadata(locale);
|
|
for (const page of pagesMetadata) {
|
|
if (!page.slug) continue;
|
|
|
|
const translatedSlug = await mapFileSlugToTranslated(page.slug, locale);
|
|
|
|
sitemapEntries.push({
|
|
url: `${baseUrl}/${locale}/${translatedSlug}`,
|
|
lastModified: new Date(),
|
|
changeFrequency: 'monthly',
|
|
priority: 0.5,
|
|
});
|
|
}
|
|
}
|
|
|
|
return sitemapEntries;
|
|
}
|