diff --git a/packages/@vuepress/core/lib/node/Page.js b/packages/@vuepress/core/lib/node/Page.js index e04bd50f72..db3a6af2d8 100644 --- a/packages/@vuepress/core/lib/node/Page.js +++ b/packages/@vuepress/core/lib/node/Page.js @@ -37,7 +37,7 @@ module.exports = class Page { */ constructor ({ - path, + path: _path, meta, title, content, @@ -58,12 +58,16 @@ module.exports = class Page { if (relative) { this.regularPath = encodeURI(fileToPath(relative)) - } else if (path) { - this.regularPath = encodeURI(path) + } else if (_path) { + this.regularPath = encodeURI(_path) } else if (permalink) { this.regularPath = encodeURI(permalink) } + if (filePath) { + this.relativePath = path.relative(context.sourceDir, filePath).replace(/\\/g, '/') + } + this.key = 'v-' + hash(`${this._filePath}${this.regularPath}`) // Using regularPath first, would be override by permalink later. this.path = this.regularPath @@ -85,11 +89,7 @@ module.exports = class Page { enhancers = [], preRender = {} }) { - // relative path - let relPath - if (this._filePath) { - relPath = path.relative(this._context.sourceDir, this._filePath) logger.developer(`static_route`, chalk.cyan(this.path)) this._content = await fs.readFile(this._filePath, 'utf-8') } else if (this._content) { @@ -124,7 +124,7 @@ module.exports = class Page { if (excerpt) { const { html } = markdown.render(excerpt, { frontmatter: this.frontmatter, - relPath + relPath: this.relativePath }) this.excerpt = html } diff --git a/packages/@vuepress/theme-default/components/Page.vue b/packages/@vuepress/theme-default/components/Page.vue index 29214521fc..0fc71105ca 100644 --- a/packages/@vuepress/theme-default/components/Page.vue +++ b/packages/@vuepress/theme-default/components/Page.vue @@ -62,7 +62,7 @@