2023-05-31 21:01:23 +00:00
|
|
|
import { PerfTimer } from "../perf"
|
|
|
|
import { QuartzFilterPlugin } from "../plugins/types"
|
|
|
|
import { ProcessedContent } from "../plugins/vfile"
|
|
|
|
|
|
|
|
export function filterContent(plugins: QuartzFilterPlugin[], content: ProcessedContent[], verbose: boolean): ProcessedContent[] {
|
|
|
|
const perf = new PerfTimer()
|
|
|
|
const initialLength = content.length
|
|
|
|
for (const plugin of plugins) {
|
2023-06-03 19:07:19 +00:00
|
|
|
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}`)
|
|
|
|
}
|
|
|
|
}
|
2023-05-31 21:01:23 +00:00
|
|
|
|
2023-06-03 19:07:19 +00:00
|
|
|
content = updatedContent
|
2023-05-31 21:01:23 +00:00
|
|
|
}
|
2023-06-03 19:07:19 +00:00
|
|
|
|
|
|
|
console.log(`Filtered out ${initialLength - content.length} files in ${perf.timeSince()}`)
|
2023-05-31 21:01:23 +00:00
|
|
|
return content
|
|
|
|
}
|