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