Skip to content

Commit a9dd135

Browse files
chore: add util file
1 parent 88a7eaf commit a9dd135

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/utils/treePluginEnhacer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const fs = require('fs');
2+
const FrontMatter = require('front-matter');
3+
4+
module.exports = function(item, options) {
5+
item.url = item.path
6+
.replace(item.extension, '')
7+
.replace(options.dir, '')
8+
.replace(/\/index$/, '')
9+
.replace(/^$/, '/');
10+
11+
if (item.type === 'file') {
12+
// remove underscore from fetched files
13+
if (item.name[0] === '_') {
14+
item.name = item.name.replace('_', '');
15+
item.url = item.url.replace('_', '');
16+
}
17+
18+
let content = fs.readFileSync(item.path, 'utf8');
19+
let { attributes } = FrontMatter(content);
20+
21+
Object.assign(item, attributes);
22+
item.anchors = []; // TODO: Add actual anchors
23+
}
24+
}

0 commit comments

Comments
 (0)