UNPKG

979 BJavaScriptView Raw
1const fs = require('fs');
2const path = require('path');
3const walk = require('walk');
4const config = require('./config');
5const md = require('./lib/marked');
6const yamlFront = require('yaml-front-matter')
7
8
9const mdData = {};
10
11
12const walker = walk.walk(config.root);
13walker.on('file', function (root, fileStats, next) {
14 const name = fileStats.name;
15 const ext = path.extname(name);
16 const basename = path.basename(name);
17
18 const file = path.resolve(__dirname, root + '/' + name);
19 // console.log(file);
20 if (ext === config.ext) {
21 const input = fs.readFileSync(file, 'utf-8');
22 const results = yamlFront.loadFront(input, 'content');
23 // console.log(results);
24
25 mdData[basename] = results;
26
27 // const res = md(results.content);
28 // console.log(res);
29
30
31 }
32
33 next();
34});
35
36
37walker.on('end', () => {
38
39 // console.log('end');
40 console.log(mdData);
41});
42
43walker.on('error', (e) => {
44 console.log(e);
45})
\No newline at end of file