starshard/peafowl
Template
1
Fork 0
mirror of https://github.com/starshardstudio/peafowl.git synced 2024-11-24 14:04:20 +00:00
peafowl/_plugins/fileData.ts

22 lines
673 B
TypeScript
Raw Normal View History

2024-06-16 11:49:13 +00:00
import {Page} from "lume/core/file.ts"
import Site from "lume/core/site.ts";
export type FileDataOptions = {
query: string,
urlizer: (data: Lume.Data) => string,
contentizer: (data: Lume.Data) => string,
}
export default function fileData({query, urlizer, contentizer}: FileDataOptions) {
return (site: Site) => {
site.addEventListener("beforeSave", () => {
const datas: Lume.Data[] = site.search.pages(query)
for(const data of datas) {
site.pages.push(Page.create({
url: urlizer(data),
content: contentizer(data),
}))
}
})
}
}