This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.js
70 lines (63 loc) · 2.09 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var showdown = require('showdown');
converter = new showdown.Converter({
tables: 'true',
simplifiedAutoLink: 'true',
});
// converter = converter.setOption('tables', 'true')
// converter = converter.setOption('simplifiedAutoLink','true');
var css = 'https://markdownpedia.tk/server/vital/style.css';
var fsExtra = require('fs-extra');
var fs = require('fs');
var search = fs.readFileSync('vital/searchtemplate.html') + '';
var template = fs.readFileSync('vital/template.html') + '';
var listofFiles = [];
fsExtra.emptyDirSync('site/html');
var e404 = fs.readFileSync('vital/404.md') + '';
var html = converter.makeHtml(e404);
html = template.replace('{markdown}', html);
fs.writeFileSync('vital/404.html', html);
getfiles('site/markdown');
function getfiles(dir) {
var files = fs.readdirSync(dir);
var i = 0;
while (i < files.length) {
var now = getSecondPart(files[i]);
if (now == 'md') {
convert(files[i], dir);
} else {
getfiles(dir + '/' + files[i]);
}
i++;
}
}
var i = 0;
var text = '';
while (i < listofFiles.length) {
var replaceText = listofFiles[i].replace('/', '');
if (replaceText == '') {
replaceText = 'home';
}
text +=
"<li><a href='#' onclick='window.location.pathname = \"" + listofFiles[i] + '";\'>' + replaceText + '</a></li>';
i++;
}
fs.writeFileSync('vital/pages/search/index.html', search.replace('{list}', text));
function convert(file, dir) {
var filename = dir + '/' + file;
var content = converter.makeHtml(fs.readFileSync(filename) + '');
filename = filename.replace('site/markdown', 'site/html');
filename = filename.replace('.md', '.html');
var data = template.replace('{markdown}', content);
checkIfDir(dir.replace('site/markdown', 'site/html'));
fs.writeFileSync(filename, data);
listofFiles.push(dir.replace('site/markdown', ''));
console.log('File is ' + file + ' and is in ' + dir);
}
function getSecondPart(str) {
return str.split('.')[1];
}
function checkIfDir(dir) {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
}