mirror of
https://github.com/andatoshiki/toshiki-notebook.git
synced 2026-06-06 00:46:29 +00:00
feat(sitemap): add feature to generate sitemap after build
This commit is contained in:
parent
b41a8ccbbf
commit
788c1bffb4
@ -1,10 +1,16 @@
|
||||
import { defineConfig } from 'vitepress'
|
||||
import { defineConfig, PageData } from 'vitepress'
|
||||
import { customElements } from './config/customElements'
|
||||
import { markdown } from './config/markdown'
|
||||
import { metaData } from './config/constants'
|
||||
import { head } from './config/head'
|
||||
import { themeConfig } from './config/theme'
|
||||
|
||||
import { SitemapStream } from 'sitemap'
|
||||
import { createWriteStream } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
const links: { url: string; lastmod: PageData['lastUpdated'] }[] = []
|
||||
|
||||
export default defineConfig({
|
||||
lang: metaData.lang, // i18n default english translation
|
||||
title: metaData.title, // title from metadata config
|
||||
@ -23,7 +29,22 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
},
|
||||
ignoreDeadLinks: true
|
||||
ignoreDeadLinks: true,
|
||||
transformHtml: (_, id, { pageData }) => {
|
||||
if (!/[\\/]404\.html$/.test(id))
|
||||
links.push({
|
||||
url: pageData.relativePath.replace(/((^|\/)index)?\.md$/, '$2'),
|
||||
lastmod: pageData.lastUpdated
|
||||
})
|
||||
},
|
||||
buildEnd: async ({ outDir }) => {
|
||||
const sitemap = new SitemapStream({ hostname: 'https://note.toshiki.dev/' })
|
||||
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))
|
||||
}
|
||||
})
|
||||
|
||||
customElements // custom element tags of markdown-it-katex in vitepress
|
||||
|
||||
@ -43,11 +43,13 @@
|
||||
"husky": "^8.0.3",
|
||||
"lint-staged": "^13.2.0",
|
||||
"markdown-it-link-preview": "^1.1.3",
|
||||
"markdown-it-table-captions": "^1.0.4",
|
||||
"markdown-it-task-lists": "^2.1.1",
|
||||
"medium-zoom": "^1.0.8",
|
||||
"mermaid": "^9.3.0",
|
||||
"prettier": "2.8.4",
|
||||
"sass": "^1.58.3",
|
||||
"sitemap": "^7.1.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"unplugin-vue-components": "^0.24.0",
|
||||
"videojs-flash": "^2.2.1",
|
||||
|
||||
14042
pnpm-lock.yaml
14042
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user