import { MetadataRoute } from "next";
import { getSortedPostsData } from "@/lib/posts";

export default function sitemap(): MetadataRoute.Sitemap {
  const baseUrl = "https://blog.gabrielkaszewski.dev";

  const posts = getSortedPostsData();

  const postUrls = posts.map((post) => ({
    url: `${baseUrl}/${post.id}`,
    lastModified: new Date(post.date).toISOString(),
    changeFrequency: "monthly" as const,
    priority: 0.8,
  }));

  const staticUrls = [
    {
      url: baseUrl,
      lastModified: new Date().toISOString(),
      changeFrequency: "weekly" as const,
      priority: 1.0,
    },
  ];

  return [...staticUrls, ...postUrls];
}
