forked from trustoverip/TechArch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (40 loc) · 1.2 KB
/
index.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
const fs = require('fs');
const showdown = require('showdown');
const replace = require('replace-in-file');
const classMap = {
h1: 'ui large header',
h2: 'ui medium header',
h3: 'ui small header',
h4: 'ui smallest header',
ul: 'ui list',
li: 'ui item'
}
const bindings = Object.keys(classMap)
.map(key => ({
type: 'output',
regex: new RegExp(`<${key}(.*)>`, 'g'),
replace: `<${key} class='${classMap[key]}' $1>`
}));
const converter = new showdown.Converter({
extensions: [...bindings]
});
function writeHTML(data) {
console.log('📝 writing docs');
fs.copyFileSync('./docs/.index.html', './docs/index.html');
console.log(data)
const options = {files: './docs/index.html', from: /<--- spec-body --->/g, to: converter.makeHtml(data),};
replace(options, (error, results) => {
if (error) {
return console.error('Error occurred:', error);
}
console.log('✅ All done!\n', results);
});
}
const readStream = fs.createReadStream('./spec.md', 'utf8');
let data = '';
console.log('📖 reading spec')
readStream.on('data', function (chunk) {
data += chunk;
}).on('end', function () {
writeHTML(data);
});