import { categories } from "@/lib/blog/config"; import { absolute, lastChanged } from "@/lib/blog/feeds"; import { listPublishedPosts } from "@/lib/blog/loader"; import { BLOG_PATH, categoryPath, postPath, RECENT_PATH, UPDATED_PATH, } from "@/lib/blog/routes"; import type { MetadataRoute } from "next"; export default async function sitemap(): Promise { const posts = await listPublishedPosts(); const newest = (list: typeof posts) => list.map(lastChanged).sort().at(-1); const updated = posts.filter((p) => p.updatedAt); return [ { url: absolute("/") }, { url: absolute("/get-started") }, { url: absolute(BLOG_PATH), lastModified: newest(posts) }, { url: absolute(RECENT_PATH), lastModified: newest(posts) }, ...(updated.length ? [{ url: absolute(UPDATED_PATH), lastModified: newest(updated) }] : []), ...categories .map((c) => ({ c, inCat: posts.filter((p) => p.category === c.slug) })) .filter(({ inCat }) => inCat.length > 0) .map(({ c, inCat }) => ({ url: absolute(categoryPath(c.slug)), lastModified: newest(inCat), })), ...posts.map((p) => ({ url: absolute(postPath(p.slug)), lastModified: lastChanged(p), })), ]; }