2023-05-30 22:02:20 +07:00
|
|
|
import { PluggableList } from "unified"
|
2023-08-17 12:04:15 +07:00
|
|
|
import { StaticResources } from "../util/resources"
|
2023-05-30 22:02:20 +07:00
|
|
|
import { ProcessedContent } from "./vfile"
|
2023-06-04 02:07:19 +07:00
|
|
|
import { QuartzComponent } from "../components/types"
|
2023-08-20 05:52:25 +07:00
|
|
|
import { FilePath, FullSlug } from "../util/path"
|
2023-08-17 12:04:15 +07:00
|
|
|
import { BuildCtx } from "../util/ctx"
|
2023-05-30 22:02:20 +07:00
|
|
|
|
2023-06-12 13:26:43 +07:00
|
|
|
export interface PluginTypes {
|
2023-07-23 07:27:41 +07:00
|
|
|
transformers: QuartzTransformerPluginInstance[]
|
|
|
|
filters: QuartzFilterPluginInstance[]
|
|
|
|
emitters: QuartzEmitterPluginInstance[]
|
2023-06-12 13:26:43 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
type OptionType = object | undefined
|
2023-07-23 07:27:41 +07:00
|
|
|
export type QuartzTransformerPlugin<Options extends OptionType = undefined> = (
|
|
|
|
opts?: Options,
|
|
|
|
) => QuartzTransformerPluginInstance
|
2023-06-12 13:26:43 +07:00
|
|
|
export type QuartzTransformerPluginInstance = {
|
|
|
|
name: string
|
2023-07-24 14:04:01 +07:00
|
|
|
textTransform?: (ctx: BuildCtx, src: string | Buffer) => string | Buffer
|
|
|
|
markdownPlugins?: (ctx: BuildCtx) => PluggableList
|
|
|
|
htmlPlugins?: (ctx: BuildCtx) => PluggableList
|
|
|
|
externalResources?: (ctx: BuildCtx) => Partial<StaticResources>
|
2023-05-30 22:02:20 +07:00
|
|
|
}
|
|
|
|
|
2023-07-23 07:27:41 +07:00
|
|
|
export type QuartzFilterPlugin<Options extends OptionType = undefined> = (
|
|
|
|
opts?: Options,
|
|
|
|
) => QuartzFilterPluginInstance
|
2023-06-12 13:26:43 +07:00
|
|
|
export type QuartzFilterPluginInstance = {
|
|
|
|
name: string
|
2023-07-24 14:04:01 +07:00
|
|
|
shouldPublish(ctx: BuildCtx, content: ProcessedContent): boolean
|
2023-06-12 13:26:43 +07:00
|
|
|
}
|
|
|
|
|
2023-07-23 07:27:41 +07:00
|
|
|
export type QuartzEmitterPlugin<Options extends OptionType = undefined> = (
|
|
|
|
opts?: Options,
|
|
|
|
) => QuartzEmitterPluginInstance
|
2023-06-12 13:26:43 +07:00
|
|
|
export type QuartzEmitterPluginInstance = {
|
|
|
|
name: string
|
2023-07-23 07:27:41 +07:00
|
|
|
emit(
|
2023-07-24 07:07:19 +07:00
|
|
|
ctx: BuildCtx,
|
2023-07-23 07:27:41 +07:00
|
|
|
content: ProcessedContent[],
|
|
|
|
resources: StaticResources,
|
|
|
|
emitCallback: EmitCallback,
|
|
|
|
): Promise<FilePath[]>
|
2023-07-24 14:04:01 +07:00
|
|
|
getQuartzComponents(ctx: BuildCtx): QuartzComponent[]
|
2023-05-30 22:02:20 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface EmitOptions {
|
2023-08-20 05:52:25 +07:00
|
|
|
slug: FullSlug
|
2023-06-17 09:41:59 +07:00
|
|
|
ext: `.${string}` | ""
|
2023-05-30 22:02:20 +07:00
|
|
|
content: string
|
|
|
|
}
|
|
|
|
|
2023-07-13 14:19:35 +07:00
|
|
|
export type EmitCallback = (data: EmitOptions) => Promise<FilePath>
|