Register a Section
Register a Section
Section titled “Register a Section”Prerequisites
Section titled “Prerequisites”Node.js 24+, Bun 1.4.0, a locally packed public core candidate and an existing Astro project. Install the schema dependency explicitly:
bun add ./alneas-sitekit-0.1.0.tgz astro zodPublic import
Section titled “Public import”Use @alneas/sitekit/sections; install the package name, not that subpath.
This framework-free registry needs no React provider or stylesheet.
Step-by-Step Implementation
Section titled “Step-by-Step Implementation”1. Define and resolve a plugin
Section titled “1. Define and resolve a plugin”Save as section.ts. The schema and component use the same section data type.
import { z } from 'zod';import { createSectionRegistry, defineSectionPlugin } from '@alneas/sitekit/sections';
const greeting = defineSectionPlugin({ type: 'greeting', schema: z.object({ type: z.literal('greeting'), title: z.string() }), component: ({ section }) => section.data.title,});const registry = createSectionRegistry([greeting]);const result = await registry.resolve( { id: 'welcome', type: 'greeting', data: { type: 'greeting', title: 'Hello' } }, { siteId: 'example', locale: 'en', pathname: '/', collectionItems: {} },);console.log(result); // Hello2. Run the section
Section titled “2. Run the section”bun section.tsVerification
Section titled “Verification”Expected output:
HelloThis verifies registry resolution. An Astro renderer must consume the resolved value to display it on a page.
Troubleshooting / Common Pitfalls
Section titled “Troubleshooting / Common Pitfalls”- Duplicate section names fail registration. Choose a unique plugin type.
- Unknown types fail resolution. Register the plugin before resolving content.
- Invalid data fails schema parsing. Keep the node type and schema literal consistent.
- Legacy names can use explicit registry aliases; the canonical plugin must already be registered.
See architecture for the reason renderer-specific domain branches stay outside the registry.