diff options
author | TimZhang <zewenzhang@gmail.com> | 2014-04-11 18:04:01 +0800 |
---|---|---|
committer | TimZhang <zewenzhang@gmail.com> | 2014-04-11 18:04:01 +0800 |
commit | 177ca32b9b77f7206bd244b4f8921b865c4a6d04 (patch) | |
tree | 38cbd1cf25afe220db40b52a5500d99538097f1f /bin/utils.js | |
parent | 892ec04f5267a2a73074087be6b4eacd13b971a2 (diff) | |
download | gitbook-177ca32b9b77f7206bd244b4f8921b865c4a6d04.zip gitbook-177ca32b9b77f7206bd244b4f8921b865c4a6d04.tar.gz gitbook-177ca32b9b77f7206bd244b4f8921b865c4a6d04.tar.bz2 |
Fix title problem when repo url doesn't have .git suffix
Diffstat (limited to 'bin/utils.js')
-rw-r--r-- | bin/utils.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/bin/utils.js b/bin/utils.js index 3aa4f18..4d45e29 100644 --- a/bin/utils.js +++ b/bin/utils.js @@ -32,15 +32,18 @@ function gitURL(path) { // Poorman's parsing // Parse a git URL to a github ID : username/reponame function githubID(_url) { + // Remove .git if it's in _url + var sliceEnd = _url.slice(-4) === '.git' ? -4 : _url.length; + // Detect HTTPS repos var parsed = url.parse(_url); if(parsed.protocol === 'https:' && parsed.host === 'github.com') { - return parsed.path.slice(1, -4); + return parsed.path.slice(1, sliceEnd); } // Detect SSH repos if(_url.indexOf('git@') === 0) { - return _url.split(':', 2)[1].slice(0, -4); + return _url.split(':', 2)[1].slice(0, sliceEnd); } // None found |