mirror of
https://github.com/wahyd4/vuepress.git
synced 2026-08-09 05:16:23 +10:00
refactor($markdown): use relativePath instead of relPath (#1485)
This commit is contained in:
@@ -124,7 +124,7 @@ module.exports = class Page {
|
||||
if (excerpt) {
|
||||
const { html } = markdown.render(excerpt, {
|
||||
frontmatter: this.frontmatter,
|
||||
relPath: this.relativePath
|
||||
relativePath: this.relativePath
|
||||
})
|
||||
this.excerpt = html
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ module.exports = function (src) {
|
||||
} = markdown.render(content, {
|
||||
loader,
|
||||
frontmatter: data,
|
||||
relPath: path.relative(sourceDir, file).replace(/\\/g, '/')
|
||||
relativePath: path.relative(sourceDir, file).replace(/\\/g, '/')
|
||||
})
|
||||
|
||||
// check if relative links are valid
|
||||
|
||||
@@ -123,7 +123,7 @@ module.exports = (markdown = {}) => {
|
||||
const parse = md.parse
|
||||
const cache = new LRUCache({ max: 1000 })
|
||||
md.parse = (src, env) => {
|
||||
const key = hash(src + env.relPath)
|
||||
const key = hash(src + env.relativePath)
|
||||
const cached = cache.get(key)
|
||||
if (cached) {
|
||||
return cached
|
||||
|
||||
@@ -11,7 +11,7 @@ module.exports = (md, externalAttrs) => {
|
||||
let hasOpenExternalLink = false
|
||||
|
||||
md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
|
||||
const { relPath } = env
|
||||
const { relativePath } = env
|
||||
const token = tokens[idx]
|
||||
const hrefIndex = token.attrIndex('href')
|
||||
if (hrefIndex >= 0) {
|
||||
@@ -28,13 +28,13 @@ module.exports = (md, externalAttrs) => {
|
||||
}
|
||||
} else if (isSourceLink) {
|
||||
hasOpenRouterLink = true
|
||||
tokens[idx] = toRouterLink(token, link, relPath)
|
||||
tokens[idx] = toRouterLink(token, link, relativePath)
|
||||
}
|
||||
}
|
||||
return self.renderToken(tokens, idx, options)
|
||||
}
|
||||
|
||||
function toRouterLink (token, link, relPath) {
|
||||
function toRouterLink (token, link, relativePath) {
|
||||
link[0] = 'to'
|
||||
let to = link[1]
|
||||
|
||||
@@ -44,8 +44,8 @@ module.exports = (md, externalAttrs) => {
|
||||
|
||||
// relative path usage.
|
||||
if (!to.startsWith('/')) {
|
||||
to = relPath
|
||||
? url.resolve('/' + relPath, to)
|
||||
to = relativePath
|
||||
? url.resolve('/' + relativePath, to)
|
||||
: ensureBeginningDotSlash(to)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user