import { MetadataRoute } from 'next';
import { fetchAllPosts } from '@/lib/rss';

const SITE_URL = 'https://alphaswords.com';

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const { posts } = await fetchAllPosts();

  const postEntries: MetadataRoute.Sitemap = posts.map(post => ({
    url: `${SITE_URL}/words/${post.slug}`,
    lastModified: post.date ? new Date(post.date) : new Date(),
    changeFrequency: 'monthly',
    priority: 0.7,
  }));

  return [
    {
      url: SITE_URL,
      lastModified: new Date(),
      changeFrequency: 'weekly',
      priority: 1,
    },
    ...postEntries,
  ];
}
