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.

TypeUsed by
SqlQueryOptionssqlQuery()
SqliteFullTextSearchOptions, SqliteFullTextSearchMethods, SqliteFullTextSearchClientMethodsfull-text search
MediaOptions, MediaMethodsthe media plugin
JsonPluginOptionsthe json plugin
YamlPluginOptionsthe yaml plugin
MarkdownPluginOptionsthe built-in markdown parser
FileParsedContextfile:parsed hook context
TypegenFieldContext, GenerateSourceTypesOptions, WriteSourceTypesOptionstype generation and typegen:field
ComarkViteOptionsthe 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.