mirror of
https://github.com/alrayyes/wiki.git
synced 2025-06-06 13:53:16 +00:00
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:
parent
af811d824f
commit
ce3dd0923b
14 changed files with 69 additions and 58 deletions
quartz/plugins/emitters
19
quartz/plugins/emitters/helpers.ts
Normal file
19
quartz/plugins/emitters/helpers.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import path from "path"
|
||||
import fs from "fs"
|
||||
import { BuildCtx } from "../../util/ctx"
|
||||
import { FilePath, FullSlug, joinSegments } from "../../util/path"
|
||||
|
||||
type WriteOptions = {
|
||||
ctx: BuildCtx
|
||||
slug: FullSlug
|
||||
ext: `.${string}` | ""
|
||||
content: string
|
||||
}
|
||||
|
||||
export const write = async ({ ctx, slug, ext, content }: WriteOptions): Promise<FilePath> => {
|
||||
const pathToPage = joinSegments(ctx.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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue