-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcss-injector.js
56 lines (47 loc) · 2.15 KB
/
css-injector.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
/*
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
GitHub HTML5 Pandoc Template: Inject CSS v1.0 (2017-11-21)
(c) Tristano Ajmone, 2017. MIT License (MIT).
https://github.com/tajmone/pandoc-goodies
//////////////////////////////////////////////////////////////////////////////
This script will:
1. Load the given template source file, which contains a placeholder string
indicating where to inject the CSS contents;
2. Load the contents of the given CSS file in memory;
3. Replace the placeholder string with the CSS contents (inject them);
4. Save the final result to the given destination file.
*/
templateFile = "GitHub_source.html5" // Template with CSS-injection placeholder
cssFile = "GitHub.min.css" // CSS source to inject into placeholder
outFile = "../GitHub.html5" // Final template output file
placeHolder = "{{CSS-INJECT}}" // Placeholder string for CSS-injection
var fs = require('fs')
// ------------------------------------------------------------------------------
// Load CSS Into Var
// ------------------------------------------------------------------------------
try {
var CSS = fs.readFileSync(cssFile, 'utf8');
} catch(e) {
console.log('Error:', e.stack);
process.exit(1);
}
// ------------------------------------------------------------------------------
// Load Template Into Var
// ------------------------------------------------------------------------------
try {
var Template = fs.readFileSync(templateFile, 'utf8');
} catch(e) {
console.log('Error:', e.stack);
process.exit(1);
}
// ------------------------------------------------------------------------------
// Inject CSS Into Template
// ------------------------------------------------------------------------------
Template = Template.replace(placeHolder, CSS);
// var result = Template.replace(placeHolder, CSS);
try {
fs.writeFileSync(outFile, Template, 'utf8');
} catch(e) {
console.log('Error:', e.stack);
process.exit(1);
}