Skip to content

Commit

Permalink
docs: feat sitemap (tensorchord#239)
Browse files Browse the repository at this point in the history
* docs: feat sitemap

Signed-off-by: han <suyanhanx@gmail.com>

* docs: sitemap url config update

Since clean url mode is not currently enabled, update the url in the sitemap to have the html suffix.

Signed-off-by: han <suyanhanx@gmail.com>

Signed-off-by: han <suyanhanx@gmail.com>
  • Loading branch information
suyanhanx committed Jan 6, 2023
1 parent 3c6fed6 commit 97ac7b9
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
26 changes: 26 additions & 0 deletions docs-zh/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { defineConfig } from 'vitepress'
import footnote from 'markdown-it-footnote'
import { sidebar } from './config/sidebar'
import { SitemapStream } from 'sitemap'
import { createWriteStream } from 'node:fs'
import { resolve } from 'node:path'

// This links array is used to temporarily store all page link information, in order to generate sitemap.
const links: any[] = []
const siteHostName = 'https://zh.envd.tensorchord.ai/'

export default defineConfig({
lang: 'zh-CN',
Expand Down Expand Up @@ -93,4 +100,23 @@ export default defineConfig({
md.use(footnote)
}
},

transformHtml: (_, id, { pageData }) => {
if (!/[\\/]404\.html$/.test(id))
links.push({
url: pageData.relativePath.replace(/\.md$/, '.html'),
lastmod: pageData.lastUpdated
})
},

buildEnd: async ({ outDir }) => {
const sitemap = new SitemapStream({
hostname: siteHostName
})
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))
},
})
28 changes: 27 additions & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { defineConfig } from 'vitepress'
import footnote from 'markdown-it-footnote'
import { sidebar } from './config/sidebar'
import { SitemapStream } from 'sitemap'
import { createWriteStream } from 'node:fs'
import { resolve } from 'node:path'

// This links array is used to temporarily store all page link information, in order to generate sitemap.
const links: any[] = []
const siteHostName = 'https://envd.tensorchord.ai/'

export default defineConfig({
lang: 'zh-CN',
Expand All @@ -25,7 +32,7 @@ export default defineConfig({
'script',
{
async: "true",
src: 'https://www.googletagmanager.com/gtag/js?id=G-HRD26FG2QW'
src: 'https://www.googletagmanager.com/gtag/js?id=G-HRD26FG2QW'
}
],
[
Expand Down Expand Up @@ -93,4 +100,23 @@ export default defineConfig({
md.use(footnote)
}
},

transformHtml: (_, id, { pageData }) => {
if (!/[\\/]404\.html$/.test(id))
links.push({
url: pageData.relativePath.replace(/\.md$/, '.html'),
lastmod: pageData.lastUpdated
})
},

buildEnd: async ({ outDir }) => {
const sitemap = new SitemapStream({
hostname: siteHostName
})
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))
},
})
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@types/markdown-it-footnote": "^3.0.0",
"prettier": "2.7.1",
"sitemap": "^7.1.1",
"vitepress": "1.0.0-alpha.33",
"vue": "^3.2.37"
},
Expand Down
54 changes: 54 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 97ac7b9

Please sign in to comment.