Initial commit
This commit is contained in:
11
server/routes/sitemap.xml.ts
Normal file
11
server/routes/sitemap.xml.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { SitemapStream, streamToPromise } from "sitemap";
|
||||
export default defineEventHandler(async (event) => {
|
||||
// Fetch all documents
|
||||
const docs = await serverQueryContent(event).find();
|
||||
const sitemap = new SitemapStream({ hostname: "https://example.com" });
|
||||
for (const doc of docs) {
|
||||
sitemap.write({ url: doc._path, changefreq: "monthly" });
|
||||
}
|
||||
sitemap.end();
|
||||
return streamToPromise(sitemap);
|
||||
});
|
Reference in New Issue
Block a user