corp sitemap generation

This commit is contained in:
tim
2025-02-18 13:41:33 -04:00
parent 65a56807de
commit 156160b041
4 changed files with 73 additions and 1 deletions

View File

@@ -1,4 +1,7 @@
import { defineConfig } from 'vitepress'
import { SitemapStream } from 'sitemap'
import { createWriteStream } from 'node:fs'
import { resolve } from 'node:path'
// https://vitepress.dev/reference/site-config
@@ -84,4 +87,26 @@ export default defineConfig({
md.disable(['replacements'], false)
},
},
// Sitemap generation
transformHtml: (_, id, { pageData }) => {
if (!/[\\/]404\.html$/.test(id))
links.push({
// you might need to change this if not using clean urls mode
url: pageData.relativePath.replace(/((^|\/)index)?\.md$/, '$2'),
lastmod: pageData.lastUpdated
})
},
buildEnd: async ({ outDir }) => {
const sitemap = new SitemapStream({
hostname: 'https://dexorder.trade/'
})
const writeStream = createWriteStream(resolve(outDir, 'sitemap.xml'))
sitemap.pipe(writeStream)
links.forEach((link) => sitemap.write(link))
sitemap.end()
await new Promise((r) => writeStream.on('finish', r))
},
})
const links = []