--- /** * Renders a page's sections by `kind`. Themes override any component through `components`; * `entries` supplies collection data for contentList sections, keyed by collection name — or by * section id for a section with a `filter`, whose entries the page resolved on their own. `media` * resolves assets in image, hero and rich-text sections (RFC-0004). Component sections (RFC-0015) * render through `Block.astro`: the theme's `blocks` map, else Cloudhal's built-in markup; rich * text places the theme's block components inside the text too (`Body.astro`). */ import type { ContentEntry, Section } from "@cloudhal/core-contracts"; import type { BlockType } from "@cloudhal/core-ts/blocks"; import type { MediaContext } from "../media.ts"; import type { SurfaceEntryCard } from "../surfaces.ts"; import Block from "./Block.astro"; import ContentList from "./ContentList.astro"; import Hero from "./Hero.astro"; import Image from "./Image.astro"; import RichText from "./RichText.astro"; import Surface from "./Surface.astro"; export type SectionComponents = Partial< Record, unknown> >; /** A theme's components for block types (RFC-0015), by type name. */ export type BlockComponents = Record; interface Props { sections: Section[]; entries?: Record; components?: SectionComponents; blocks?: BlockComponents; /** The theme's block types (`src/blocks.ts`): checked before its components render them. */ blockTypes?: readonly BlockType[]; media?: MediaContext; /** Surfaces' entry sources by section id, then data key (`loadSurfaceSources`, RFC-0020 §3). */ surfaceSources?: Record>; } const { sections, entries = {}, components = {}, blocks = {}, blockTypes, media, surfaceSources = {}, } = Astro.props; const defaults = { hero: Hero, richText: RichText, image: Image, contentList: ContentList }; type AnyComponent = (props: never) => unknown; const resolved = { ...defaults, ...components } as Record< Exclude, AnyComponent | undefined >; --- {sections.map((section) => { if (section.kind === "component") return ; if (section.kind === "surface") return ; const Component = resolved[section.kind]; if (!Component) return
; return section.kind === "contentList" ? : section.kind === "richText" ? : ; })}