2023-06-17 09:41:59 +07:00
|
|
|
import { QuartzEmitterPlugin } from "../types"
|
|
|
|
import path from "path"
|
|
|
|
|
2023-06-20 10:37:45 +07:00
|
|
|
export type ContentIndex = Map<string, ContentDetails>
|
2023-06-19 00:47:07 +07:00
|
|
|
export type ContentDetails = {
|
2023-06-17 09:41:59 +07:00
|
|
|
title: string,
|
|
|
|
links?: string[],
|
|
|
|
tags?: string[],
|
|
|
|
content: string,
|
2023-06-19 00:47:07 +07:00
|
|
|
}
|
2023-06-17 09:41:59 +07:00
|
|
|
|
2023-06-20 10:37:45 +07:00
|
|
|
export const ContentIndex: QuartzEmitterPlugin = () => {
|
2023-06-17 09:41:59 +07:00
|
|
|
return {
|
|
|
|
name: "ContentIndex",
|
|
|
|
async emit(_contentDir, _cfg, content, _resources, emit) {
|
2023-06-19 00:47:07 +07:00
|
|
|
const fp = path.join("static", "contentIndex")
|
2023-06-17 09:41:59 +07:00
|
|
|
const linkIndex: ContentIndex = new Map()
|
2023-06-20 10:37:45 +07:00
|
|
|
for (const [_tree, file] of content) {
|
|
|
|
let slug = file.data.slug!
|
2023-06-17 09:41:59 +07:00
|
|
|
linkIndex.set(slug, {
|
|
|
|
title: file.data.frontmatter?.title!,
|
2023-06-20 10:37:45 +07:00
|
|
|
links: file.data.links ?? [],
|
2023-06-17 09:41:59 +07:00
|
|
|
tags: file.data.frontmatter?.tags,
|
|
|
|
content: file.data.text ?? ""
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
await emit({
|
|
|
|
content: JSON.stringify(Object.fromEntries(linkIndex)),
|
|
|
|
slug: fp,
|
|
|
|
ext: ".json",
|
|
|
|
})
|
|
|
|
|
|
|
|
return [`${fp}.json`]
|
|
|
|
},
|
|
|
|
getQuartzComponents: () => [],
|
|
|
|
}
|
|
|
|
}
|