fix: add change log routes to the sitemap

This commit is contained in:
Dorian Niemiec 2024-09-07 22:06:58 +02:00
parent dc11ef8aef
commit da4973954e

View file

@ -1,4 +1,5 @@
import { getAllBlogPostSlugs } from "@/lib/getBlogPost"; import { getAllBlogPostSlugs } from "@/lib/getBlogPost";
import clientPromise from "@/lib/db";
export default async function sitemap() { export default async function sitemap() {
const blogPostSlugs = await getAllBlogPostSlugs(); const blogPostSlugs = await getAllBlogPostSlugs();
@ -25,5 +26,16 @@ export default async function sitemap() {
lastModified: new Date().toISOString().split("T")[0] lastModified: new Date().toISOString().split("T")[0]
})); }));
return [...baseRoutes, ...blogRoutes]; let changelogRoutes = [];
try {
const client = await clientPromise;
const db = client.db(process.env.MONGODB_DB);
const slugs = await db.collection("pages").find().toArray();
changelogRoutes = slugs.map((slug) => ({
url: `https://svrjs.vercel.app/changelog/${slug.slug}`,
lastModified: new Date().toISOString().split("T")[0]
}));
} catch (err) {}
return [...baseRoutes, ...blogRoutes, ...changelogRoutes];
} }