Files
e-tib.com/app/sitemap.ts
Marc Mintel d14122005d Initial commit: E-TIB production hardening & E2E foundation
Former-commit-id: ef04fca3d76375630c05aac117bf586953f3b657
2026-04-28 19:11:38 +02:00

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;
}