Jacky Zhao
2023-07-24 9e83af04a78d5988bd517bcc61c48998bbfa17ef
quartz/processors/filter.ts
@@ -0,0 +1,27 @@
import { BuildCtx } from "../ctx"
import { PerfTimer } from "../perf"
import { QuartzFilterPluginInstance } from "../plugins/types"
import { ProcessedContent } from "../plugins/vfile"
export function filterContent(
  { cfg, argv }: BuildCtx,
  content: ProcessedContent[],
): ProcessedContent[] {
  const perf = new PerfTimer()
  const initialLength = content.length
  for (const plugin of cfg.plugins.filters) {
    const updatedContent = content.filter(plugin.shouldPublish)
    if (argv.verbose) {
      const diff = content.filter((x) => !updatedContent.includes(x))
      for (const file of diff) {
        console.log(`[filter:${plugin.name}] ${file[1].data.slug}`)
      }
    }
    content = updatedContent
  }
  console.log(`Filtered out ${initialLength - content.length} files in ${perf.timeSince()}`)
  return content
}