addPageComponent #

Declares that the page being rendered uses component.

Usage #

TypeScript
import { 
addPageComponent
} from 'kawapress'
const
env
= {}
addPageComponent
(
env
, {
name
: 'AcmeChart',
from
: 'acme/chart' })

Parameters

envPageComponentEnv

The Markdown env of the rule that produced the tag.

pathoptionalstring

Public route of the page being rendered. Only used in error messages.

pageComponentsoptionalPageComponent[]

The components the page has declared so far. KawaPress reads them after rendering.

[key: string]unknown

The Markdown env of markdown-it and markdown-exit carries every value a plugin writes. Accepting that shape here lets a plugin pass the env it receives straight to addPageComponent().

componentPageComponent

The tag name and the module that provides it.

namestring

Name of the tag in the page template, for example AcmeChart in <AcmeChart />. It becomes the import binding of the page SFC, so it must be a valid JavaScript identifier.

fromstring

Module whose default export is the component: a bare package specifier or an absolute file path. Vite resolves it from the page that imports it.

Notes #

Call it with the env of the rule that produced the tag. Declaring the same name and module twice is harmless, because a page can render a component many times; declaring the same name from two modules is an error.

Full type signature
TypeScript
function addPageComponent(env: PageComponentEnv, component: PageComponent): void

Edit this page

Comments