提交 a7b1ce7a 编写于 作者: D DCloud_LXH

feat: add base to md

上级 396eee2c
...@@ -13,8 +13,10 @@ const changeLoaderOptions = (options, key = 'name') => { ...@@ -13,8 +13,10 @@ const changeLoaderOptions = (options, key = 'name') => {
return options; return options;
}; };
const base = '/uniCloud/'
const config = { const config = {
base: '/uniCloud/', base,
theme: 'vuepress-theme-uni-app-test', theme: 'vuepress-theme-uni-app-test',
title: 'uniCloud', title: 'uniCloud',
description: 'uniCloud Document', description: 'uniCloud Document',
...@@ -115,6 +117,9 @@ const config = { ...@@ -115,6 +117,9 @@ const config = {
.end() .end()
.plugin('markdown-it-raw-table') .plugin('markdown-it-raw-table')
.use(require('markdown-it-raw-table')) .use(require('markdown-it-raw-table'))
.end()
.plugin('add-base-to-md')
.use(require('./markdown/add-base-to-md'), [{ base }])
} }
}, },
chainWebpack (config, isServer) { chainWebpack (config, isServer) {
......
module.exports = function (md, { base = '/' }) {
if (base !== '/') {
md.core.ruler.after('inline', 'add-base-to-md', function (state) {
state.tokens.forEach(function (blockToken) {
if (blockToken.type === 'inline' && blockToken.content && blockToken.children && blockToken.children.length) {
if (blockToken.content.indexOf('](/') > -1) {
blockToken.children.forEach(function (inlineToken) {
if (inlineToken.type === 'link_open' && inlineToken.attrs && inlineToken.attrs.length) {
inlineToken.attrs.forEach(function (attr) {
if (attr[0] === 'href' && attr[1].indexOf('/') === 0 && attr[1].indexOf(base) !== 0) {
attr[1] = base + attr[1].slice(1)
}
});
}
})
}
}
});
return false;
});
}
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册