Skip to content

Commit 0127e74

Browse files
committed
Merge pull request #21 from igorshubovych/static-site-zip
Fix #12, #19: download pages zip archive from tldr-pages.github.io static site instead of Github API
2 parents 2c73276 + 2683302 commit 0127e74

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"repository" : "tldr-pages/tldr",
32
"colors": {
43
"text": "green",
54
"command-background": "black",

lib/remote.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,23 @@ if (config.get().proxy) {
1616
}
1717

1818
exports.download = function(done) {
19-
2019
var src = source();
21-
var url = 'https://github.com/' + src.user + '/' + src.repo + '/archive/' + src.branch + '.zip';
20+
var url = 'http://tldr-pages.github.io/assets/tldr.zip';
2221
var target = path.join(os.tmpdir(), 'tldr');
23-
var inside = path.join(target, src.repo + '-' + src.branch);
22+
var inside = target;
23+
if (src) {
24+
url = 'https://github.com/' + src.user + '/' + src.repo + '/archive/' + src.branch + '.zip';
25+
inside = path.join(target, src.repo + '-' + src.branch);
26+
}
2427

2528
rimraf.sync(target);
2629
mkdirp.sync(target);
2730

2831
var extractor = unzip.Extract({path: target});
29-
extractor.on('error', done);
30-
extractor.on('finish', function() {
32+
extractor.on('error', function (e) {
33+
done(new Error('Cannot update from ' + url), inside);
34+
});
35+
extractor.on('close', function() {
3136
done(null, inside);
3237
});
3338

@@ -38,16 +43,17 @@ exports.download = function(done) {
3843

3944
req.on('error', done);
4045
req.pipe(extractor);
41-
4246
}
4347

4448
function source() {
45-
var parts = config.get().repository.split('#');
46-
var github = parts[0].match(/^(.*)\/(.*)$/);
47-
return {
48-
user: github[1],
49-
repo: github[2],
50-
branch: parts[1] || 'master'
51-
};
52-
49+
var repository = config.get().repository;
50+
if (repository) {
51+
var parts = repository.split('#');
52+
var github = parts[0].match(/^(.*)\/(.*)$/);
53+
return {
54+
user: github[1],
55+
repo: github[2],
56+
branch: parts[1] || 'master'
57+
};
58+
}
5359
}

0 commit comments

Comments
 (0)