Files
website/app/sitemap.ts
Steffen Illium 941e0a66f3
Some checks failed
Next.js App CI / docker (push) Failing after 59s
Metadata Canocical pages
2025-09-22 09:41:53 +02:00

61 lines
1.6 KiB
TypeScript

// app/sitemap.ts
import { getAllTags, getSortedPostsData } from '@/lib/posts';
import { MetadataRoute } from 'next';
import { DATA } from './resume';
export default function sitemap(): MetadataRoute.Sitemap {
const baseUrl = DATA.url;
// Improvement 1: Fetch all posts with a single, more efficient call
const allPosts = getSortedPostsData();
const postUrls: MetadataRoute.Sitemap = allPosts.map((post) => ({
url: `${baseUrl}/${post.href}`,
lastModified: new Date(post.date),
changeFrequency: 'yearly',
priority: 0.7,
}));
const allTags = getAllTags(2);
const tagUrls: MetadataRoute.Sitemap = allTags.map((tag) => ({
url: `${baseUrl}/tags/${tag.name}`,
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.5,
}));
// The types for changeFrequency and lastModified will now be correctly inferred
const staticRoutes: MetadataRoute.Sitemap = [
{
url: baseUrl,
lastModified: new Date(),
priority: 1,
changeFrequency: 'monthly',
},
{
url: `${baseUrl}/experience`,
lastModified: new Date(),
priority: 0.8,
changeFrequency: 'monthly',
},
{
url: `${baseUrl}/research`,
lastModified: new Date(),
priority: 0.9,
changeFrequency: 'yearly',
},
{
url: `${baseUrl}/publications`,
lastModified: new Date(),
priority: 0.9,
changeFrequency: 'yearly',
},
{
url: `${baseUrl}/tags`,
lastModified: new Date(),
priority: 0.7,
changeFrequency: 'monthly',
},
];
return [...staticRoutes, ...postUrls, ...tagUrls];
}