astro-ghostcms/packages/astro-ghostcms-rendercontent/lib/GhostRender.astro

21 lines
630 B
Plaintext
Raw Normal View History

---
import type { SanitizeOptions } from 'ultrahtml/transformers/sanitize'
import { createComponentProxy, html } from './utils';
export interface Props {
content?: string;
sanitize?: SanitizeOptions;
components?: Record<string, any>;
}
const input = Astro.props.content ?? await Astro.slots.render('default');
if (!input) {
throw new Error('Unable to render <GhostRender> without a content prop or children')
}
// @ts-ignore
const components = createComponentProxy($$result, Astro.props.components);
const content = await html(input, { sanitize: Astro.props.sanitize, components });
---
<Fragment set:html={content} />