-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (38 loc) · 1.23 KB
/
app.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
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const jsdom = require("jsdom");
const beautify = require('js-beautify').html;
const showdown = require('showdown');
const { JSDOM } = jsdom;
const JSoptions = {
contentType: 'text/html',
};
const Showdownoptions = {};
var converter = new showdown.Converter(Showdownoptions);
var mdfile;
const publicDir = './_public';
if (!fs.existsSync(publicDir)){
fs.mkdirSync(publicDir);
}
function convertToMarkdown(mark)
{
mdfile = fs.readFileSync(mark, 'utf8');
converter.setFlavor('vanilla');
return converter.makeHtml(mdfile);
}
JSDOM.fromFile("index.html", JSoptions).then(dom => {
// Get md file from directory
glob(__dirname + '/*.md', {}, (err, files)=>{
files.forEach(function (file) {
console.log(file);
markFile = path.basename(file, '.md');
dom.window.document.getElementById(markFile).innerHTML = convertToMarkdown(file);
});
})
var fileName = publicDir+'/index.html';
var stream = fs.createWriteStream(fileName);
stream.once('open', function(fd) {
stream.end(beautify(dom.serialize(), { indent_size: 2, space_in_empty_paren: true }));
});
});