Plugin types
The plugin-contract and plugin option and method types exported by comark-content.
The types describing the Content instance and client plugin contracts, plus the option and method bags each plugin contributes.
Every export is re-exported from the main comark-content entry point:
import type {
ContentPlugin,
ContentPluginContext,
ContentClientPlugin,
} from 'comark-content'ContentPlugin
The interface a plugin implements: a single optional setup hook.
interface ContentPlugin<Methods extends Record<string, any> = Record<string, never>> {
setup?: (content: ContentPluginContext) => Methods | void | Promise<Methods | void>
}ContentPluginContext
The content handle passed to a plugin's setup: the manifest, cache, hooks, and registration helpers.
interface ContentPluginContext {
options: ContentOptions
hooks: Hookable<ContentHooks>
cache: Cache
manifest: Manifest
init: (opts?: { partial?: boolean; ignoreCache?: boolean }) => Promise<void>
stat: (key: string) => ContentListFile | undefined
getSource: (name: string) => Source | undefined
loadSnapshot: (sourceName: string) => Promise<void> | void
addParser: (extensions: `.${string}`[], parse: Parser) => void
addListingFields: (extensions: `.${string}`[], fields: string[]) => void
addServeHandler: (path: string, handler: (request: Request) => Promise<Response>) => void
update: (sourceName: string, file: ContentFile) => Promise<void>
remove: (sourceName: string, key: string) => Promise<void>
}The defineContentPlugin helper handles the generics for you:
export default defineContentPlugin<Options, Methods>((options) => ({
setup(content) { /* ... */ return methodsToMerge },
}))ContentClientPlugin
The interface a client plugin implements. Build one with defineContentClientPlugin.
interface ContentClientPlugin<Methods extends Record<string, any> = Record<string, never>> {
setup?: (client: ContentClientWithOptions) => Methods | void
}Plugin option and method types
Per-plugin option and method bags, each documented in full on its feature page.
| Type | Used by |
|---|---|
SqlQueryOptions | sqlQuery() |
SqliteFullTextSearchOptions, SqliteFullTextSearchMethods, SqliteFullTextSearchClientMethods | full-text search |
MediaOptions, MediaMethods | the media plugin |
JsonPluginOptions | the json plugin |
YamlPluginOptions | the yaml plugin |
MarkdownPluginOptions | the built-in markdown parser |
FileParsedContext | file:parsed hook context |
TypegenFieldContext, GenerateSourceTypesOptions, WriteSourceTypesOptions | type generation and typegen:field |
ComarkViteOptions | the comark-content/vite plugin |
MergePluginMethods<P> | Intersection of the method maps contributed by Content plugins. |
MergeClientPluginMethods<P> | Intersection of the method maps contributed by client plugins. |