docs: added documentation on init() for component plugins
Some checks are pending
Build and Test / build-and-test (macos-latest) (push) Waiting to run
Build and Test / build-and-test (windows-latest) (push) Waiting to run
Build and Test / build-and-test (ubuntu-latest) (push) Has been skipped
Build and Test / publish-tag (push) Has been skipped
Deploy v5 Preview / Deploy v5 to Cloudflare Pages (push) Has been skipped
Docker build & push image / build (push) Has been skipped

This commit is contained in:
saberzero1 2026-03-16 14:31:16 +01:00
parent 4bb075cc64
commit 24634934d1
No known key found for this signature in database
2 changed files with 33 additions and 0 deletions

View File

@ -201,6 +201,37 @@ export const layout = await loadQuartzLayout({
}) })
``` ```
### Receiving YAML Options in Component-Only Plugins
Component plugins that also belong to a processing category (transformer, filter, emitter, page type) receive options through their factory function automatically. However, **component-only plugins** — those whose manifest declares only `"category": ["component"]` — are loaded via side-effect import and don't go through the factory path.
To receive YAML options in a component-only plugin, export an `init` function from your entry point:
```ts title="src/index.ts"
export function init(options?: Record<string, unknown>): void {
// options contains merged defaultOptions + user's YAML options
const myFlag = (options?.myFlag as boolean) ?? false
// Use options to configure registrations, global state, etc.
}
```
Quartz's config-loader calls `init()` after importing the module, passing the merged result of your manifest's `defaultOptions` and the user's `options` from `quartz.config.yaml`. The merge follows the same `{ ...defaultOptions, ...userOptions }` pattern used for processing plugins — user values take precedence.
Declare your defaults in `package.json`:
```json title="package.json"
{
"quartz": {
"category": ["component"],
"defaultOptions": {
"myFlag": false
}
}
}
```
If your plugin does not export `init`, it continues to work as a pure side-effect import — this is fully backward compatible.
## Internal Components ## Internal Components
Quartz also has internal components that provide layout utilities. These live in `quartz/components/` and are primarily used for structural purposes: Quartz also has internal components that provide layout utilities. These live in `quartz/components/` and are primarily used for structural purposes:

View File

@ -536,3 +536,5 @@ npx quartz plugin prune --dry-run
## Component Plugins ## Component Plugins
For plugins that provide visual components (like Explorer, Graph, Search), see the [[creating components|creating component plugins]] guide. For plugins that provide visual components (like Explorer, Graph, Search), see the [[creating components|creating component plugins]] guide.
Component-only plugins (those with `"category": ["component"]` in their manifest) are loaded via side-effect import rather than a factory function. If your component-only plugin needs to receive user options from `quartz.config.yaml`, export an `init(options)` function — see [[creating components#Receiving YAML Options in Component-Only Plugins|receiving YAML options]] for details.