提交 8907c5cb 编写于 作者: D DCloud_LXH

feat: createSiteMap

上级 9532aacf
......@@ -2,9 +2,7 @@ const { slugify } = require('@vuepress/shared-utils')
const translatePlugin = require('./markdown/translate')
const headerPlugin = require('./markdown/header')
const createSidebar = require('./markdown/createSidebar')
const { simplifySlugText } = require('./utils')
const tabs = ['/uniCloud/', '/plugin/', '/worktile/', '/tutorial/', '/collocation/', '/component/', '/api/', '/']
const { simplifySlugText, tabs } = require('./utils')
const config = {
// TODO use theme
......
......@@ -14,7 +14,10 @@ function simplifySlugText(text) {
return text;
}
const tabs = ['/uniCloud/', '/plugin/', '/worktile/', '/tutorial/', '/collocation/', '/component/', '/api/', '/']
module.exports = {
isExternal,
simplifySlugText
simplifySlugText,
tabs
}
\ No newline at end of file
......@@ -8,7 +8,8 @@
},
"scripts": {
"dev": "vuepress dev docs",
"build": "node --max_old_space_size=3072 ./node_modules/vuepress/cli.js build docs --no-cache"
"build": "node ./script/createSiteMap.js && node --max_old_space_size=3072 ./node_modules/vuepress/cli.js build docs --no-cache",
"sitemap": "node ./script/createSiteMap.js"
},
"repository": {
"type": "git",
......@@ -31,4 +32,4 @@
"dependencies": {
"@docsearch/js": "^3.0.0-alpha.50"
}
}
}
\ No newline at end of file
此差异已折叠。
const path = require('path');
const fs = require('fs');
const MarkdownIt = require('markdown-it');
const { tabs, isExternal } = require('../docs/.vuepress/utils');
const domain = 'https://zh.uniapp.dcloud.io'
const links = []
const xmlBefore = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
`
const xmlAfter = `\n</urlset> `
tabs.forEach(tab => {
parseBar(path.join(__dirname, '../docs', tab, '_sidebar.md'))
})
const xmlItems = links.map(url => {
return ` <url>
<loc>${url}</loc>
</url>`
})
fs.writeFileSync('./root/sitemap.xml', xmlBefore + xmlItems.join('\n') + xmlAfter)
function parseBar(file) {
new MarkdownIt()
.parse(fs.readFileSync(file, { encoding: 'utf-8' }))
.forEach(token => {
if (token.type === 'inline') {
let [_, text, link] = token.content.match(/\[(.+?)\]\((.+?)\)/) || token.content.match(/(.+)/)
if (link && !isExternal(link)) {
link = domain + path.join('/', link.replace(/\.md\b/, '')
.replace(/\bREADME\b/, '')
.replace(/\/index/, '/')
.replace(/\?id=/, '#'))
.replace(/\\/g, '/')
links.push(link)
}
}
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册