Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix($theme-default): fix editLink for repos hosted on gitlab.com #2523

Merged
merged 3 commits into from Aug 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/@vuepress/theme-default/components/PageEdit.vue
Expand Up @@ -80,8 +80,8 @@ export default {
methods: {
createEditLink (repo, docsRepo, docsDir, docsBranch, path) {
const bitbucket = /bitbucket.org/
if (bitbucket.test(repo)) {
const base = outboundRE.test(docsRepo) ? docsRepo : repo
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second expression (repo) of the ternary operator would never get executed in the refactored implementation, since the value of docsRepo must be a full url (it must contain the bitbucket.org string), which means that it will always match the outboundRE regex pattern (which is /^[a-z]+:/i (from line 4 of packages/@vuepress/theme-default/util/index.js)), so the base variable would always get its initial value from docsRepo.

I tried to understand the original intention behind this line, but it just seemed to be wrong to me: if docsRepo had been defined by the user as group(or user)/project (like vuejs/vuepress), then the base variable used the value of repo, which is the url of the main site's repo, and not the repo of the docs. Not to mention, that a group(or user)/project-style docsRepo value suggests a GitHub repo and not a BitBucket one.

if (bitbucket.test(docsRepo)) {
const base = docsRepo
return (
base.replace(endingSlashRE, '')
+ `/src`
Expand All @@ -92,12 +92,24 @@ export default {
)
}

const gitlab = /gitlab.com/
if (gitlab.test(docsRepo)) {
bencodezen marked this conversation as resolved.
Show resolved Hide resolved
const base = docsRepo
return (
base.replace(endingSlashRE, '')
+ `/-/edit`
+ `/${docsBranch}/`
+ (docsDir ? docsDir.replace(endingSlashRE, '') + '/' : '')
+ path
)
}

const base = outboundRE.test(docsRepo)
? docsRepo
: `https://github.com/${docsRepo}`
return (
base.replace(endingSlashRE, '')
+ `/edit`
+ '/edit'
+ `/${docsBranch}/`
+ (docsDir ? docsDir.replace(endingSlashRE, '') + '/' : '')
+ path
Expand Down