-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
32 lines (26 loc) · 1.13 KB
/
build.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
const fs = require('fs/promises');
const path = require('path');
const Markdoc = require('@markdoc/markdoc');
const mkdirp = require('mkdirp');
main()
async function main() {
await recursiveScan(path.join(__dirname, 'markdown'));
}
async function recursiveScan(directory) {
for (const file of await fs.readdir(directory)) {
try {
var stat = await fs.stat(path.join(directory, file));
} catch (e) { continue; } /* Bad file or permission error, ignore and continue */
if (stat.isDirectory()) {
await recursiveScan(path.join(directory, file));
} else {
const ast = Markdoc.parse(await fs.readFile(path.join(directory, file), 'utf8'));
const content = Markdoc.transform(ast, /* config */);
const html = Markdoc.renderers.html(content);
// lol
mkdirp.sync(path.join(__dirname, 'build', path.relative(path.join(__dirname, 'markdown'), path.join(directory, file.split('.')[0]))));
const newPath = path.join(__dirname, 'build', path.relative(path.join(__dirname, 'markdown'), path.join(directory, file.split('.')[0], 'index.html')));
await fs.writeFile(newPath, html);
}
}
}