Skip to content

Register a Section

Bun, registry access, and an existing project using the framework. Install the schema dependency explicitly:

Terminal window
bun add @dataarthub/eaos-host-site-astro astro zod

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); // Hello
Terminal window
bun section.ts

Expected output:

Hello

This verifies registry resolution. An Astro renderer must consume the resolved value to display it on a page.

  • 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.