wiki/quartz/processors/emit.ts

34 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

import { PerfTimer } from "../util/perf"
import { getStaticResourcesFromPlugins } from "../plugins"
import { ProcessedContent } from "../plugins/vfile"
import { QuartzLogger } from "../util/log"
import { trace } from "../util/trace"
import { BuildCtx } from "../util/ctx"
2023-07-02 20:08:29 +00:00
2023-07-24 00:09:12 +00:00
export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
const { argv, cfg } = ctx
const perf = new PerfTimer()
const log = new QuartzLogger(ctx.argv.verbose)
log.start(`Emitting output files`)
2023-07-22 23:06:36 +00:00
let emittedFiles = 0
2023-07-24 07:04:01 +00:00
const staticResources = getStaticResourcesFromPlugins(ctx)
for (const emitter of cfg.plugins.emitters) {
2023-06-04 17:37:43 +00:00
try {
const emitted = await emitter.emit(ctx, content, staticResources)
2023-06-04 17:37:43 +00:00
emittedFiles += emitted.length
if (ctx.argv.verbose) {
2023-06-04 17:37:43 +00:00
for (const file of emitted) {
console.log(`[emit:${emitter.name}] ${file}`)
}
}
2023-06-04 17:37:43 +00:00
} catch (err) {
trace(`Failed to emit from plugin \`${emitter.name}\``, err as Error)
}
}
log.end(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince()}`)
}