Jacky Zhao
2023-07-23 ae2e3b463a91d94caa8bdf62e5c3a3d726b8b4e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { PerfTimer } from "../perf"
import { QuartzFilterPluginInstance } from "../plugins/types"
import { ProcessedContent } from "../plugins/vfile"
 
export function filterContent(
  plugins: QuartzFilterPluginInstance[],
  content: ProcessedContent[],
  verbose: boolean,
): ProcessedContent[] {
  const perf = new PerfTimer()
  const initialLength = content.length
  for (const plugin of plugins) {
    const updatedContent = content.filter(plugin.shouldPublish)
 
    if (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
}