--- import type { ImageSection } from "@cloudhal/core-contracts"; import { safeSrc } from "../markdown.ts"; import { assetCaption, imageAttributes, type MediaContext } from "../media.ts"; interface Props { section: ImageSection; /** Assets of the page's source, transform and locale (RFC-0004 ยง7.5). */ media?: MediaContext; } const { section, media } = Astro.props; // An `assetId` resolves through the source; otherwise (or for a reader without media) `src` is used. const asset = section.image.assetId ? media?.assets?.get(section.image.assetId) : undefined; const defaultLocale = media?.defaultLocale ?? media?.locale ?? "en"; const locale = media?.locale ?? defaultLocale; const attrs = asset ? imageAttributes(asset, section.image, { locale, defaultLocale, transform: media?.transform ?? "none", ...(media?.budget ? { budget: media.budget } : {}), sizes: "(min-width: 48rem) 48rem, 100vw", ...(media?.preview ? { preview: true } : {}), }) : undefined; // Section fields can be written by agents: only safe URL schemes reach the page. const src = attrs ? undefined : safeSrc(section.image.src); const caption = asset ? assetCaption(asset, locale, defaultLocale, section.caption) : section.caption; ---
{attrs && {attrs.alt}} {src && {section.image.alt}} {caption &&
{caption}
}