Jacky Zhao
2023-08-17 2f6747b1666316e579c6e7238092ac6a65d00925
quartz/processors/emit.ts
@@ -1,13 +1,13 @@
import path from "path"
import fs from "fs"
import { PerfTimer } from "../perf"
import { PerfTimer } from "../util/perf"
import { getStaticResourcesFromPlugins } from "../plugins"
import { EmitCallback } from "../plugins/types"
import { ProcessedContent } from "../plugins/vfile"
import { FilePath } from "../path"
import { QuartzLogger } from "../log"
import { trace } from "../trace"
import { BuildCtx } from "../ctx"
import { FilePath, joinSegments } from "../util/path"
import { QuartzLogger } from "../util/log"
import { trace } from "../util/trace"
import { BuildCtx } from "../util/ctx"
export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
  const { argv, cfg } = ctx
@@ -16,7 +16,7 @@
  log.start(`Emitting output files`)
  const emit: EmitCallback = async ({ slug, ext, content }) => {
    const pathToPage = path.join(argv.output, slug + ext) as FilePath
    const pathToPage = joinSegments(argv.output, slug + ext) as FilePath
    const dir = path.dirname(pathToPage)
    await fs.promises.mkdir(dir, { recursive: true })
    await fs.promises.writeFile(pathToPage, content)
@@ -24,7 +24,7 @@
  }
  let emittedFiles = 0
  const staticResources = getStaticResourcesFromPlugins(cfg.plugins)
  const staticResources = getStaticResourcesFromPlugins(ctx)
  for (const emitter of cfg.plugins.emitters) {
    try {
      const emitted = await emitter.emit(ctx, content, staticResources, emit)
@@ -37,7 +37,6 @@
      }
    } catch (err) {
      trace(`Failed to emit from plugin \`${emitter.name}\``, err as Error)
      throw err
    }
  }