refactor: move emit from callback to helper file function (#704)
* Change emit from callback to helpers file function * Update docs, remove commented code, improve type sig
This commit is contained in:
		@@ -1,10 +1,6 @@
 | 
			
		||||
import path from "path"
 | 
			
		||||
import fs from "fs"
 | 
			
		||||
import { PerfTimer } from "../util/perf"
 | 
			
		||||
import { getStaticResourcesFromPlugins } from "../plugins"
 | 
			
		||||
import { EmitCallback } from "../plugins/types"
 | 
			
		||||
import { ProcessedContent } from "../plugins/vfile"
 | 
			
		||||
import { FilePath, joinSegments } from "../util/path"
 | 
			
		||||
import { QuartzLogger } from "../util/log"
 | 
			
		||||
import { trace } from "../util/trace"
 | 
			
		||||
import { BuildCtx } from "../util/ctx"
 | 
			
		||||
@@ -15,19 +11,12 @@ export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
 | 
			
		||||
  const log = new QuartzLogger(ctx.argv.verbose)
 | 
			
		||||
 | 
			
		||||
  log.start(`Emitting output files`)
 | 
			
		||||
  const emit: EmitCallback = async ({ slug, ext, content }) => {
 | 
			
		||||
    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)
 | 
			
		||||
    return pathToPage
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  let emittedFiles = 0
 | 
			
		||||
  const staticResources = getStaticResourcesFromPlugins(ctx)
 | 
			
		||||
  for (const emitter of cfg.plugins.emitters) {
 | 
			
		||||
    try {
 | 
			
		||||
      const emitted = await emitter.emit(ctx, content, staticResources, emit)
 | 
			
		||||
      const emitted = await emitter.emit(ctx, content, staticResources)
 | 
			
		||||
      emittedFiles += emitted.length
 | 
			
		||||
 | 
			
		||||
      if (ctx.argv.verbose) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user