Skip to content

Commit 1970167

Browse files
committed
added dynamic sitemap
1 parent 5fa14e3 commit 1970167

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

app/sitemap.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { headers } from "next/headers";
2+
import { getPostsForSite } from "@/lib/fetchers";
3+
4+
export default async function Sitemap() {
5+
const headersList = headers();
6+
const domain =
7+
headersList
8+
.get("host")
9+
?.replace(".localhost:3000", `.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}`) ??
10+
"vercel.pub";
11+
12+
const posts = await getPostsForSite(domain);
13+
14+
return [
15+
{
16+
url: `https://${domain}`,
17+
lastModified: new Date(),
18+
},
19+
...posts.map(({ slug }) => ({
20+
url: `https://${domain}/${slug}`,
21+
lastModified: new Date(),
22+
})),
23+
];
24+
}

0 commit comments

Comments
 (0)