public/server/routes/sitemap.xml.ts

14 lines
470 B
TypeScript
Raw Normal View History

2022-07-22 15:32:00 -04:00
import { serverQueryContent } from "#content/server";
import { SitemapStream, streamToPromise } from "sitemap";
export default defineEventHandler(async (event) => {
// Fetch all documents
const docs = await serverQueryContent(event).find();
2022-11-01 00:07:14 -04:00
const sitemap = new SitemapStream({ hostname: "https://eggworld.me" });
2022-07-22 15:32:00 -04:00
for (const doc of docs) {
sitemap.write({ url: doc._path, changefreq: "monthly" });
}
sitemap.end();
return streamToPromise(sitemap);
});