forked from Charles7c/charles7c.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
article.data.js
25 lines (23 loc) · 777 Bytes
/
article.data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import fs from 'node:fs';
import path from 'node:path';
import parseFrontmatter from 'gray-matter';
const excludedFiles = ['index.md', 'tags.md', 'archives.md', 'me.md'];
export default {
watch: ['./docs/**/*.md'],
load(watchedFiles) {
// 排除不必要文件
const articleFiles = watchedFiles.filter(file => {
const filename = path.basename(file);
return !excludedFiles.includes(filename);
});
// 解析文章 Frontmatter
return articleFiles.map(articleFile => {
const articleContent = fs.readFileSync(articleFile, 'utf-8');
const { data } = parseFrontmatter(articleContent);
return {
...data,
path: articleFile.substring(articleFile.lastIndexOf('/docs/') + 6).replace(/\.md$/, ''),
}
})
}
}