-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkerria.config.ts
56 lines (50 loc) · 1.46 KB
/
kerria.config.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
import { readFile } from "node:fs/promises";
import matter from "gray-matter";
import { createProcessor, useLoad, useSource } from "../packages/core/src";
const processor = createProcessor("Kerria", () => {
const meta = useLoad("meta", {
out: "./dist/meta.json",
onUpdate(newVal, oldVal) {
newVal.chapters = oldVal?.chapters ?? {};
return newVal;
},
beforeOutput(val) {
const chapters = Object.entries(val.chapters)
.sort(([a], [b]) => a.localeCompare(b))
.map(([, data]) => data);
return {
...val,
chapters
};
}
});
useSource(0, {
base: "./posts",
dist: "./dist/posts",
ext: ".md",
async parse(path, info) {
const file = await readFile(path);
const text = file.toString();
const { data, content } = matter(text);
await info.output(path, content);
return {
data
};
},
onCacheHit(cache) {
const { data } = cache;
const { title } = data;
meta.value.chapters[title] = {
title,
...data
};
},
unlink(cache) {
const { data } = cache;
const { title } = data;
delete meta.value.chapters[title];
}
});
});
processor.build();
processor.watch();