From 9bfb0fc3b733fc0983da072ac07c330721ee1ba6 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Wed, 31 Jan 2024 14:41:05 +0800 Subject: [PATCH] fix: markdown normalizeLink --- docs/.vuepress/markdown/createSidebar.js | 14 +++++++----- docs/.vuepress/markdown/normallizeLink.js | 26 +++++++++++------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/docs/.vuepress/markdown/createSidebar.js b/docs/.vuepress/markdown/createSidebar.js index 10c5654f..d02dffba 100644 --- a/docs/.vuepress/markdown/createSidebar.js +++ b/docs/.vuepress/markdown/createSidebar.js @@ -46,11 +46,15 @@ function parseBar(tab, file, options) { } } - link = path.join('/', link.replace(/\.md\b/, '') - .replace(/\bREADME\b/, '') - .replace(/\/index/, '/') - .replace(/\?id=/, '#')) - .replace(/\\/g, '/') + link = path.join( + '/', + link + .replace(/(\bREADME\.md\b)|(\bREADME(?!\.))/i, 'index.html') // README.md | README | readme.md | readme -> index.html + .replace(/(\bindex\.md\b)|(index(?!\.))/, 'index.html') // /index -> /index.html + .replace(/\.md\b/, '.html') // *.md -> *.html + .replace(/\?id=/, '#') // ?id= -> # + .replace(/\\/g, '/') // \ -> / + ) links.push(link) } diff --git a/docs/.vuepress/markdown/normallizeLink.js b/docs/.vuepress/markdown/normallizeLink.js index 4511bf59..2d97c9c3 100644 --- a/docs/.vuepress/markdown/normallizeLink.js +++ b/docs/.vuepress/markdown/normallizeLink.js @@ -16,17 +16,17 @@ function normalizeLink(url) { } module.exports = function (md) { - md.normalizeLink = (function (oldNormalizeLink) { - return function (url) { - url = isExternal(url) - ? url - : normalizeLink(url) - .replace(/\.md\b/, '.html') - .replace(/\bREADME\b/, 'index.html') - .replace(/\/index(?!\.)/, 'index.html') - .replace(/\?id=/, '#') - .replace(/\\/g, '/') - return oldNormalizeLink.bind(this)(url) - } - })(md.normalizeLink) + md.normalizeLink = (function (oldNormalizeLink) { + return function (url) { + url = isExternal(url) + ? url + : normalizeLink(url) + .replace(/(\bREADME\.md\b)|(\bREADME(?!\.))/i, 'index.html') // README.md | README | readme.md | readme -> index.html + .replace(/(\bindex\.md\b)|(index(?!\.))/, 'index.html') // /index -> /index.html + .replace(/\.md\b/, '.html') // *.md -> *.html + .replace(/\?id=/, '#') // ?id= -> # + .replace(/\\/g, '/') // \ -> / + return oldNormalizeLink.bind(this)(url) + } + })(md.normalizeLink) } \ No newline at end of file -- GitLab