--- /** * A component section (RFC-0015 ยง5): the theme's own component for the type when it maps one * (`blocks` in theme.ts, given `{ section, props, content, contentHtml, media }`), else Cloudhal's * built-in markup (`renderComponentSection`). Props are checked against the type first (the * theme's types from `src/blocks.ts`); unknown types and props that do not fit render nothing. */ import type { ComponentSection } from "@cloudhal/core-contracts"; import type { BlockType } from "@cloudhal/core-ts/blocks"; import { renderComponentSection, themeRegistry } from "../blocks.ts"; import { renderMarkdown } from "../markdown.ts"; import type { MediaContext } from "../media.ts"; interface Props { section: ComponentSection; media?: MediaContext; /** The theme's components by block type name. */ blocks?: Record; /** The theme's block types (`src/blocks.ts`). */ blockTypes?: readonly BlockType[]; } const { section, media, blocks = {}, blockTypes } = Astro.props; type AnyComponent = (props: never) => unknown; const registry = themeRegistry(blockTypes); const Own = blocks[section.type] as AnyComponent | undefined; // A type the theme declares must fit; one it only maps a component for is its own business. const fits = (registry.checkSection(section.type, section.props) ?? []).length === 0; const content = typeof section.props.content === "string" ? section.props.content : undefined; const contentHtml = content !== undefined ? renderMarkdown(content, media) : undefined; --- {Own ? ( fits && (
) ) : ( )}