import type { MetadataRoute } from 'next';
import { getAllPosts } from '@/lib/mdx';

export default function sitemap(): MetadataRoute.Sitemap {
    const posts = getAllPosts();
    const latestPostDate = posts[0]?.date ? new Date(posts[0].date) : undefined;

    const blogEntries: MetadataRoute.Sitemap = posts.map((post) => ({
        url: `https://akkolli.net/blog/${post.slug}`,
        lastModified: new Date(post.date),
    }));

    return [
        { url: 'https://akkolli.net', lastModified: latestPostDate },
        { url: 'https://akkolli.net/projects', lastModified: new Date('2024-10-26') },
        { url: 'https://akkolli.net/projects/graph-attention-topology', lastModified: new Date('2024-10-26') },
        { url: 'https://akkolli.net/blog', lastModified: latestPostDate },
        { url: 'https://akkolli.net/resume' },
        ...blogEntries,
    ];
}
