From ff4b5563818840e5da2d71757b07574d56232fcd Mon Sep 17 00:00:00 2001 From: kbot Date: Mon, 6 Jul 2026 20:50:16 -0500 Subject: [PATCH] feat(seo): add build-time sitemap --- app/sitemap.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/sitemap.ts diff --git a/app/sitemap.ts b/app/sitemap.ts new file mode 100644 index 0000000..412c6db --- /dev/null +++ b/app/sitemap.ts @@ -0,0 +1,20 @@ +import type { MetadataRoute } from 'next' +import { getAllTags, getPosts } from '@/lib/posts' +import { tagToSlug } from '@/lib/tags' + +const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://localhost:3000' + +export const dynamic = 'force-static' + +const absoluteUrl = (pathname: string): string => new URL(pathname, siteUrl).toString() + +const [posts, tags] = await Promise.all([getPosts(), getAllTags()]) + +export default function sitemap(): MetadataRoute.Sitemap { + return [ + { url: absoluteUrl('/') }, + { url: absoluteUrl('/blog/') }, + ...posts.map((post) => ({ url: absoluteUrl(`/blog/${post.slug}/`) })), + ...tags.map((tag) => ({ url: absoluteUrl(`/blog/tags/${tagToSlug(tag.label)}/`) })), + ] +}