提交 0e9054f8 编写于 作者: D DCloud_LXH

chore: createSiteMap

上级 4f3cfbba
......@@ -3,6 +3,9 @@ const path = require('path')
const MarkdownIt = require('markdown-it');
const createMarkdownArray = require('./createMarkdownArray')
const { isExternal } = require('../utils')
const createSiteMap = require('./createSiteMap');
const links = []
function parseBar(file, options) {
const textName = options.text || 'text'
......@@ -14,15 +17,17 @@ function parseBar(file, options) {
.forEach(token => {
if (token.type === 'inline') {
let [_, text, link] = token.content.match(/\[(.+?)\]\((.+?)\)/) || token.content.match(/(.+)/)
link = link && (
isExternal(link)
? link
: path.join('/', link.replace(/\.md\b/, '')
if (link && !isExternal(link)) {
link = path.join('/', link.replace(/\.md\b/, '')
.replace(/\bREADME\b/, '')
.replace(/\/index/, '/')
.replace(/\?id=/, '#'))
.replace(/\\/g, '/')
)
links.push(link)
}
contents.push({
level: token.level,
[textName]: text,
......@@ -36,11 +41,15 @@ function parseBar(file, options) {
module.exports = function (tabs = []) {
const sidebar = {}
tabs.forEach(tab => {
sidebar[tab] = parseBar(path.join(__dirname, '../../', tab, '_sidebar.md'), {
text: 'title',
link: 'path'
})
})
createSiteMap(links, () => links.length = 0)
return tabs.length ? sidebar : false
}
\ No newline at end of file
const fs = require('fs')
const path = require('path')
const domain = 'https://zh.uniapp.dcloud.io'
const xmlBefore = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
`
const xmlAfter = `\n</urlset>`
module.exports = (links, callback = () => { }) => {
const xmlItems = links.map(url => {
return ` <url>
<loc>${domain + url}</loc>
</url>`
}).join('\n')
fs.writeFile(
path.resolve(__dirname, '../../../root/sitemap.xml'),
xmlBefore + xmlItems + xmlAfter,
{ encoding: 'utf-8' },
callback
)
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
},
"scripts": {
"dev": "vuepress dev docs",
"build": "node ./script/createSiteMap.js && node --max_old_space_size=3072 ./node_modules/vuepress/cli.js build docs --no-cache",
"build": "node --max_old_space_size=3072 ./node_modules/vuepress/cli.js build docs --no-cache",
"sitemap": "node ./script/createSiteMap.js"
},
"repository": {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册