Register a Section
Register a Section
Section titled “Register a Section”Prerequisites
Section titled “Prerequisites”Bun, registry access, and an existing project using the framework. Install the schema dependency explicitly:
bun add @dataarthub/eaos-host-site-astro astro zodStep-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 '@dataarthub/eaos-host-site-astro/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.
Common Pitfalls
Section titled “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.