From 5479d6ef07519ebaede2f4d21e57f5e4ee8ce1e1 Mon Sep 17 00:00:00 2001 From: Dalton <3844467+daltondiaz@users.noreply.github.com> Date: Tue, 12 Jun 2018 14:50:45 -0300 Subject: [PATCH] fix: edit page from Bitbucket (#569) --- lib/default-theme/Page.vue | 39 ++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/lib/default-theme/Page.vue b/lib/default-theme/Page.vue index 9dfd9912a7..17957e7563 100644 --- a/lib/default-theme/Page.vue +++ b/lib/default-theme/Page.vue @@ -87,17 +87,8 @@ export default { } else { path += '.md' } - if (docsRepo && editLinks) { - const base = outboundRE.test(docsRepo) - ? docsRepo - : `https://github.com/${docsRepo}` - return ( - base.replace(endingSlashRE, '') + - `/edit/${docsBranch}` + - (docsDir ? '/' + docsDir.replace(endingSlashRE, '') : '') + - path - ) + return this.createEditLink(repo, docsRepo, docsDir, docsBranch, path) } }, editLinkText () { @@ -107,6 +98,34 @@ export default { `Edit this page` ) } + }, + methods: { + createEditLink (repo, docsRepo, docsDir, docsBranch, path) { + const bitbucket = /bitbucket.org/ + if (bitbucket.test(repo)) { + const base = outboundRE.test(docsRepo) + ? docsRepo + : repo + return ( + base.replace(endingSlashRE, '') + + `/${docsBranch}` + + (docsDir ? '/' + docsDir.replace(endingSlashRE, '') : '') + + path + + `?mode=edit&spa=0&at=${docsBranch}&fileviewer=file-view-default` + ) + } + + const base = outboundRE.test(docsRepo) + ? docsRepo + : `https://github.com/${docsRepo}` + + return ( + base.replace(endingSlashRE, '') + + `/edit/${docsBranch}` + + (docsDir ? '/' + docsDir.replace(endingSlashRE, '') : '') + + path + ) + } } }