Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 6823100

Browse files
committed
docs: add sitemap functionality
1 parent 9497c12 commit 6823100

File tree

3 files changed

+84
-83
lines changed

3 files changed

+84
-83
lines changed

apps/docs/.vitepress/config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import {defineConfig} from 'vitepress'
22
import Icons from 'unplugin-icons/vite'
3+
import {createWriteStream} from 'node:fs'
4+
import {resolve} from 'node:path'
5+
import {SitemapStream} from 'sitemap'
36

47
const title = 'BootstrapVueNext'
58
const description = 'Quickly and Easily Integrate Bootstrap V5 Components With Vue 3'
9+
const links: {url: string; lastmod: number | undefined}[] = []
610

711
// https://vitepress.dev/reference/site-config
812
export default defineConfig({
@@ -30,4 +34,22 @@ export default defineConfig({
3034
},
3135
},
3236
appearance: false,
37+
transformHtml: (_, id, {pageData}) => {
38+
if (!/[\\/]404\.html$/.test(id))
39+
links.push({
40+
// you might need to change this if not using clean urls mode
41+
url: pageData.relativePath.replace(/((^|\/)index)?\.md$/, '$2'),
42+
lastmod: pageData.lastUpdated,
43+
})
44+
},
45+
buildEnd: async ({outDir}) => {
46+
const sitemap = new SitemapStream({
47+
hostname: 'https://subwork.xyz/',
48+
})
49+
const writeStream = createWriteStream(resolve(outDir, 'sitemap.xml'))
50+
sitemap.pipe(writeStream)
51+
links.forEach((link) => sitemap.write(link))
52+
sitemap.end()
53+
await new Promise((r) => writeStream.on('finish', r))
54+
},
3355
})

apps/docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"eslint-define-config": "^1.21.0",
2828
"eslint-plugin-vue": "^9.15.1",
2929
"prettier": "^2.8.8",
30+
"sitemap": "^7.1.1",
3031
"typescript": "^5.1.3",
3132
"unplugin-icons": "^0.16.3",
3233
"vitepress": "1.0.0-beta.3",

pnpm-lock.yaml

Lines changed: 61 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)