-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.data.js
More file actions
43 lines (40 loc) · 1.11 KB
/
Copy patharticle.data.js
File metadata and controls
43 lines (40 loc) · 1.11 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import fs from "node:fs";
import path from "node:path";
import parseFrontmatter from "gray-matter";
const excludedFiles = [
"index.md",
"tags.md",
"archives.md",
];
export default {
watch: ["./docs/categories/**/*.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);
const filePath = articleFile
.substring(articleFile.lastIndexOf("/docs/") + 17)
.replace(/\.md$/, "");
const [classify, year, month, day, title] = filePath.split("/");
return {
...data,
path: articleFile
.substring(articleFile.lastIndexOf("/docs/") + 6)
.replace(/\.md$/, ""),
pageInfo: {
classify,
year,
month,
day,
title,
},
};
});
},
};