From cc193d5cc1c29a0ff802ca6bf13fdf6887047604 Mon Sep 17 00:00:00 2001 From: Shigma <33423008+Shigma@users.noreply.github.com> Date: Thu, 28 Mar 2019 01:09:21 +0800 Subject: [PATCH] refactor($markdown): use `relativePath` instead of `relPath` (#1485) --- packages/@vuepress/core/lib/node/Page.js | 2 +- packages/@vuepress/markdown-loader/index.js | 2 +- packages/@vuepress/markdown/index.js | 2 +- packages/@vuepress/markdown/lib/link.js | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/@vuepress/core/lib/node/Page.js b/packages/@vuepress/core/lib/node/Page.js index db3a6af2d8..5172dbd716 100644 --- a/packages/@vuepress/core/lib/node/Page.js +++ b/packages/@vuepress/core/lib/node/Page.js @@ -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 } diff --git a/packages/@vuepress/markdown-loader/index.js b/packages/@vuepress/markdown-loader/index.js index 196d9344b2..5d19d6d1d7 100644 --- a/packages/@vuepress/markdown-loader/index.js +++ b/packages/@vuepress/markdown-loader/index.js @@ -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 diff --git a/packages/@vuepress/markdown/index.js b/packages/@vuepress/markdown/index.js index fdb0481fbe..f3b4a38c77 100644 --- a/packages/@vuepress/markdown/index.js +++ b/packages/@vuepress/markdown/index.js @@ -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 diff --git a/packages/@vuepress/markdown/lib/link.js b/packages/@vuepress/markdown/lib/link.js index 6e8d2a0445..48551b4e51 100644 --- a/packages/@vuepress/markdown/lib/link.js +++ b/packages/@vuepress/markdown/lib/link.js @@ -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) }