From 0df0778a8401450f311c328d244d5885ea24198c Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Fri, 24 Feb 2017 11:09:50 +0100 Subject: [PATCH 1/2] Handles GitBook root configuration option --- assets/plugin.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/assets/plugin.js b/assets/plugin.js index 787dc1d..9ed2fae 100644 --- a/assets/plugin.js +++ b/assets/plugin.js @@ -30,7 +30,27 @@ require([ 'gitbook' ], function (gitbook) { label: 'Edit on GitHub', position: 'right', onClick: function() { - window.open('https://github.com/' + defaultOption.repo + '/edit/' + defaultOption.branch + '/' + gitbook.state.filepath); + + let editUrl = 'https://github.com/' + defaultOption.repo + '/edit/' + defaultOption.branch + '/'; + let docsRoot = defaultOption.root; + if(docsRoot){ + + //removes ./ at the beginning, if any + if(docsRoot.startsWith('./')){ + docsRoot = docsRoot.substr(2); + } + + //removes trailing /, if any + if(docsRoot.endsWith('/')){ + docsRoot = docsRoot.substr(0, docsRoot.length - 1); + } + + editUrl += docsRoot; + } + + editUrl += ('/' + gitbook.state.filepath); + + window.open(editUrl); } }); }; From 7d27d8e2fb7fa9a58a35e01b473d52fec002620f Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Fri, 24 Feb 2017 11:14:45 +0100 Subject: [PATCH 2/2] pick root from the correct config object --- assets/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/plugin.js b/assets/plugin.js index 9ed2fae..e96ff3b 100644 --- a/assets/plugin.js +++ b/assets/plugin.js @@ -32,7 +32,7 @@ require([ 'gitbook' ], function (gitbook) { onClick: function() { let editUrl = 'https://github.com/' + defaultOption.repo + '/edit/' + defaultOption.branch + '/'; - let docsRoot = defaultOption.root; + let docsRoot = config.root; if(docsRoot){ //removes ./ at the beginning, if any