Skip to content
This repository was archived by the owner on Jan 27, 2019. It is now read-only.

Commit 29422d7

Browse files
authored
Merge pull request #44 from layoutanalysis/master
getcss cli options to configure timeout, enable json output and stripping of wayback css
2 parents ca8cf9b + 1bb4315 commit 29422d7

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

bin/getcss

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ var normalizeUrl = require('normalize-url');
66
var getCss = require('..');
77

88
program
9-
.version('0.0.1')
10-
.command('* <url>')
11-
.action(function(url) {
9+
.version('0.0.2')
10+
.usage('[options] <url>')
11+
.option("-j, --json","output downloaded html and css as json")
12+
.option("-t, --timeout [ms]","timeout in ms to wait for responses", 30000)
13+
.option("-s, --strip_wayback_css","remove wayback toolbar css from internet archive captures")
14+
.action(function(url, options) {
1215
if(url) {
1316
url = normalizeUrl(url, { stripWWW: false });
14-
getCss(url, { verbose: true }).then(function(css) {
15-
console.log(css.css);
17+
getCss(url, { verbose: true, timeout: options.timeout, stripWayback: options.strip_wayback_css }).then(function(css) {
18+
if (options.json){
19+
console.log(JSON.stringify(css));
20+
}
21+
else {
22+
console.log(css.css);
23+
}
1624
});
1725
}
1826
});

index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
"use strict";
2-
31
var q = require("q");
42
var isCss = require("is-css");
53
var isPresent = require("is-present");
64
var isBlank = require("is-blank");
75
var isUrl = require("is-url-superb");
8-
var request = require("request");
6+
var request = require("requestretry");
97
var cheerio = require("cheerio");
108
var normalizeUrl = require("normalize-url");
119
var stripHtmlComments = require("strip-html-comments");
10+
var stripWaybackToolbar = require("strip-wayback-toolbar")
1211
var resolveCssImportUrls = require("resolve-css-import-urls");
1312
var ua = require("ua-string");
1413

1514
var getLinkContents = require("./utils/get-link-contents");
1615
var createLink = require("./utils/create-link");
1716

18-
module.exports = function(url, options, html) {
17+
module.exports = function(url, options, html){
1918
var deferred = q.defer();
2019
var options = options || {};
2120
options.headers = options.headers || {};
2221
options.headers["User-Agent"] = options.headers["User-Agent"] || ua;
2322
options.timeout = options.timeout || 5000;
23+
options.stripWayback = options.stripWayback || false;
2424
options.gzip = true;
2525

2626
if (typeof url !== "string" || isBlank(url) || !isUrl(url)) {
@@ -52,16 +52,20 @@ module.exports = function(url, options, html) {
5252
}
5353

5454
function parseHtml(html) {
55+
if (options.stripWayback) {
56+
html = stripWaybackToolbar(html);
57+
}
5558
var $ = cheerio.load(html);
5659
result.pageTitle = $("head > title").text();
60+
result.html = html;
5761

5862
$("[rel=stylesheet]").each(function() {
59-
var link = $(this).attr("href");
60-
if (isPresent(link)) {
61-
result.links.push(createLink(link, url));
62-
} else {
63-
result.styles.push(stripHtmlComments($(this).text()));
64-
}
63+
var link = $(this).attr("href");
64+
if (isPresent(link)) {
65+
result.links.push(createLink(link, url));
66+
} else{
67+
result.styles.push(stripHtmlComments($(this).text()));
68+
}
6569
});
6670

6771
$("style").each(function() {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
"normalize-url": "^1.8.0",
2222
"q": "^1.4.1",
2323
"request": "^2.79.0",
24+
"requestretry": "^1.13.0",
2425
"resolve-css-import-urls": "1.0.0",
2526
"strip-html-comments": "1.0.0",
27+
"strip-wayback-toolbar": "^1.0.4",
2628
"ua-string": "^1.0.0"
2729
},
2830
"devDependencies": {

0 commit comments

Comments
 (0)