forked from iansinnott/date-fns-dash-docset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process-html.js
executable file
·73 lines (62 loc) · 1.6 KB
/
process-html.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
69
70
71
72
73
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { map, pipe, trim } = require('ramda');
const cheerio = require('cheerio');
const stripIndent = require('strip-indent');
const { fromReadableStream } = require('./utils.js');
const heredoc = pipe(trim, stripIndent);
const processHTML = (html) => {
const $ = cheerio.load(html);
// Strip out the redundant text from document titles
const $title = $('head > title');
$title.text($title.text().replace(' - modern JavaScript date utility library', ''))
// Add custom styles
$('head').append(heredoc(`
<style>
.ui .docs-finder {
display: none;
}
.ui .docs {
padding-top: 0;
}
.ui .docs_nav_bar {
display: none;
}
.ui .docs-content {
padding-left: 0;
}
.ui .jsdoc_usage-options .jsdoc_usage-option:not(:first-child) {
display: none;
}
</style>
`));
// Remove non-local scripts. These docs are meant for offline use so let's not
// pull in any remote scripts
$('script')
.filter((i, el) => {
const src = $(el).attr('src');
return !/^\/assets\/js/.test(src);
})
.remove();
// Remove unecessary meta tags
$('meta')
.filter((i, el) => {
const name = $(el).attr('name') || $(el).attr('property');
return /^(twitter|og):/.test(name);
})
.remove();
return $.html();
};
const main = pipe(
fromReadableStream,
map(trim),
map(processHTML)
);
main(process.stdin).subscribe(
result => console.log(result),
err => {
console.error(err);
process.exit(1);
},
);