quartz-research-note/quartz/plugins/types.ts

55 lines
1.7 KiB
TypeScript
Raw Normal View History

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