-
Notifications
You must be signed in to change notification settings - Fork 1
/
uncss.js
68 lines (58 loc) · 1.82 KB
/
uncss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var http = require('http'),
parseString = require('xml2js').parseString,
uncss = require('uncss'),
fs = require('fs');
var options = {
host: 'localhost',
port: '8000',
path: '/sitemap.xml'
}
var uncss_options = {
stylesheets: ['/static/css/tachyons/css/tachyons.min.css'],
csspath: '/static/css/tachyons/css/tachyons.min.css'
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}
function createCSS(urls) {
uncss(urls, uncss_options, function (error, output) {
if (error) {
return console.log(error);
}
console.log(output)
var hardcoded_output = replaceAll(output, "url\\(\\.\\.\\/", "url(/static/")
fs.writeFile("common/templates/common/css.html", hardcoded_output, function (err) {
if (err) {
return console.log(err);
}
console.log("common/templates/common/css.html saved!");
});
fs.writeFile("common/static/specific/phillydsa-style.min.css", output, function (err) {
if (err) {
return console.log(err);
}
console.log("common/static/specific/phillydsa-style.min.css saved!");
});
});
}
request = http.request(options, function (res) {
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
parseString(data, function (err, result) {
var urlArray = result['urlset']['url']
var urlList = []
for (var i = 0; i < urlArray.length; i++) {
urlList.push(urlArray[i]['loc'][0]);
}
console.log(urlList)
createCSS(urlList)
});
});
});
request.on('error', function (e) {
console.log(e.message);
});
request.end();