mirror of
https://github.com/starshardstudio/peafowl.git
synced 2024-11-22 13:04:20 +00:00
22 lines
673 B
TypeScript
22 lines
673 B
TypeScript
|
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),
|
||
|
}))
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|