Skip to content

Commit

Permalink
fix($theme-default): fix wrong editLink (close: #1115, #1125) (#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma authored and ulivz committed Mar 12, 2019
1 parent cb02f26 commit 3b14375
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
16 changes: 8 additions & 8 deletions packages/@vuepress/core/lib/node/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = class Page {
*/

constructor ({
path,
path: _path,
meta,
title,
content,
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
22 changes: 8 additions & 14 deletions packages/@vuepress/theme-default/components/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</template>

<script>
import { resolvePage, normalize, outboundRE, endingSlashRE } from '../util'
import { resolvePage, outboundRE, endingSlashRE } from '../util'
export default {
props: ['sidebarItems'],
Expand Down Expand Up @@ -116,14 +116,8 @@ export default {
docsRepo = repo
} = this.$site.themeConfig
let path = normalize(this.$page.path)
if (endingSlashRE.test(path)) {
path += 'README.md'
} else {
path += '.md'
}
if (docsRepo && editLinks) {
return this.createEditLink(repo, docsRepo, docsDir, docsBranch, path)
if (docsRepo && editLinks && this.$page.relativePath) {
return this.createEditLink(repo, docsRepo, docsDir, docsBranch, this.$page.relativePath)
}
},
Expand All @@ -146,8 +140,8 @@ export default {
return (
base.replace(endingSlashRE, '')
+ `/src`
+ `/${docsBranch}`
+ (docsDir ? '/' + docsDir.replace(endingSlashRE, '') : '')
+ `/${docsBranch}/`
+ (docsDir ? docsDir.replace(endingSlashRE, '') + '/' : '')
+ path
+ `?mode=edit&spa=0&at=${docsBranch}&fileviewer=file-view-default`
)
Expand All @@ -156,11 +150,11 @@ export default {
const base = outboundRE.test(docsRepo)
? docsRepo
: `https://github.com/${docsRepo}`
return (
base.replace(endingSlashRE, '')
+ `/edit/${docsBranch}`
+ (docsDir ? '/' + docsDir.replace(endingSlashRE, '') : '')
+ `/edit`
+ `/${docsBranch}/`
+ (docsDir ? docsDir.replace(endingSlashRE, '') + '/' : '')
+ path
)
}
Expand Down

0 comments on commit 3b14375

Please sign in to comment.