1- var path = require ( "path " ) ;
1+ var urlJoin = require ( "url-join " ) ;
22var BugReporter = require ( "./BugReporter" ) ;
33var findAllPositions = require ( "position-map-text-to-markdown" ) . findAllPositions ;
44
@@ -20,26 +20,26 @@ function getContentAsync(apiURL) {
2020
2121function getResourceURL ( config , filePath , branch ) {
2222 if ( config [ "markdownBaseURL" ] ) {
23- return path . join ( config [ "markdownBaseURL" ] , filePath ) ;
23+ return urlJoin ( config [ "markdownBaseURL" ] , filePath ) ;
2424 }
25- return `https://github.com/${ config . repo } / blob/ ${ branch } / ${ filePath } `
25+ return urlJoin ( `https://github.com/` , config . repo , ` blob` , branch , filePath ) ;
2626}
2727
2828function getEditURL ( config , filePath , branch ) {
29- return `https://github.com/${ config . repo } / edit/ ${ branch } / ${ filePath } `
29+ return urlJoin ( `https://github.com/` , config . repo , ` edit` , branch , filePath ) ;
3030}
3131function getAPIURL ( config , filePath ) {
3232 if ( config [ "githubAPIBaseURL" ] ) {
33- return path . join ( config [ "githubAPIBaseURL" ] , filePath ) ;
33+ return urlJoin ( config [ "githubAPIBaseURL" ] , filePath ) ;
3434 }
35- return `https://api.github.com/repos/${ config . repo } / contents/ ${ filePath } ` ;
35+ return urlJoin ( `https://api.github.com/repos/` , config . repo , ` contents` , filePath ) ;
3636}
3737
3838function getIssueURL ( config ) {
3939 if ( config [ "newIssueURL" ] ) {
4040 return config [ "newIssueURL" ] ;
4141 }
42- return `https://github.com/${ config . repo } /issues/new`
42+ return urlJoin ( `https://github.com/` , config . repo , ` /issues/new`) ;
4343}
4444window . require ( [ "gitbook" ] , function ( gitbook ) {
4545 // plugin config
@@ -51,8 +51,9 @@ window.require(["gitbook"], function(gitbook) {
5151 reportElement . setAttribute ( "style" , "position:fixed; right:0;bottom:0;" ) ;
5252 var clickEvent = ( "ontouchstart" in window ) ? "touchend" : "click" ;
5353 reportElement . addEventListener ( clickEvent , function ( event ) {
54- var apiURL = getAPIURL ( config , gitbook . state . filepath ) ;
55- var resourceURL = getResourceURL ( config , gitbook . state . filepath , "master" ) ;
54+ var pathname = urlJoin ( gitbook . state . config . root , gitbook . state . filepath ) ;
55+ var apiURL = getAPIURL ( config , pathname ) ;
56+ var resourceURL = getResourceURL ( config , pathname , "master" ) ;
5657 var editURL = getEditURL ( config , gitbook . state . filepath , "master" ) ;
5758 getContentAsync ( apiURL ) . then ( function ( markdown ) {
5859 var bug = new BugReporter ( getIssueURL ( config ) ) ;
0 commit comments