quartz-research-note/quartz/processors/filter.ts

25 lines
815 B
TypeScript
Raw Normal View History

import { BuildCtx } from "../util/ctx"
import { PerfTimer } from "../util/perf"
import { ProcessedContent } from "../plugins/vfile"
2023-07-24 07:04:01 +00:00
export function filterContent(ctx: BuildCtx, content: ProcessedContent[]): ProcessedContent[] {
const { cfg, argv } = ctx
const perf = new PerfTimer()
const initialLength = content.length
for (const plugin of cfg.plugins.filters) {
2023-07-24 07:04:01 +00:00
const updatedContent = content.filter((item) => plugin.shouldPublish(ctx, item))
2023-06-03 19:07:19 +00:00
if (argv.verbose) {
2023-07-23 00:27:41 +00:00
const diff = content.filter((x) => !updatedContent.includes(x))
2023-06-03 19:07:19 +00:00
for (const file of diff) {
console.log(`[filter:${plugin.name}] ${file[1].data.slug}`)
}
}
2023-06-03 19:07:19 +00:00
content = updatedContent
}
2023-06-03 19:07:19 +00:00
console.log(`Filtered out ${initialLength - content.length} files in ${perf.timeSince()}`)
return content
}