コンテンツにスキップ

Register a Section

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 ./eaos-host-site-astro-0.0.0-public-candidate.1.tgz astro zod

Use @dataarthub/eaos-host-site-astro/sections; install the package name, not that subpath. This framework-free registry needs no React provider or stylesheet.

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
ターミナルウィンドウ
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.