feat(seo): add build-time sitemap
This commit is contained in:
20
app/sitemap.ts
Normal file
20
app/sitemap.ts
Normal file
@@ -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)}/`) })),
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user