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