mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-27 05:46:22 +00:00
ce3dd0923b
* Change emit from callback to helpers file function * Update docs, remove commented code, improve type sig
19 lines
589 B
TypeScript
19 lines
589 B
TypeScript
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
|
|
}
|