Files
penx/app/sitemap.ts
2024-08-05 10:06:02 +08:00

25 lines
578 B
TypeScript

import { headers } from "next/headers";
import { getPostsForSpace } from "@/lib/fetchers";
export default async function Sitemap() {
const headersList = headers();
const domain =
headersList
.get("host")
?.replace(".localhost:3000", `.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}`) ??
"vercel.pub";
const posts = await getPostsForSpace(domain);
return [
{
url: `https://${domain}`,
lastModified: new Date(),
},
...posts.map(({ slug }) => ({
url: `https://${domain}/${slug}`,
lastModified: new Date(),
})),
];
}