keroosha.cybergulag.today/quartz/plugins/types.ts

56 lines
1.6 KiB
TypeScript
Raw Normal View History

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