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