Skip to content

Commit

Permalink
refactor($markdown): use relativePath instead of relPath (#1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma authored and ulivz committed Mar 27, 2019
1 parent d7b8daf commit cc193d5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/@vuepress/core/lib/node/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@vuepress/markdown-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/@vuepress/markdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions packages/@vuepress/markdown/lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]

Expand All @@ -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)
}

Expand Down

0 comments on commit cc193d5

Please sign in to comment.