summaryrefslogtreecommitdiffstats
path: root/bin/utils.js
diff options
context:
space:
mode:
authorTimZhang <zewenzhang@gmail.com>2014-04-11 18:04:01 +0800
committerTimZhang <zewenzhang@gmail.com>2014-04-11 18:04:01 +0800
commit177ca32b9b77f7206bd244b4f8921b865c4a6d04 (patch)
tree38cbd1cf25afe220db40b52a5500d99538097f1f /bin/utils.js
parent892ec04f5267a2a73074087be6b4eacd13b971a2 (diff)
downloadgitbook-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.js7
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