CASOON Open Source
Astro components, rendered without an Astro page.
A thin runtime around Astro's Container API. Pass a component and props, get HTML or a Response back: for HTMX fragments, emails, OG cards, CMS blocks and edge handlers.
npm install @casoon/fragment-rendererpnpm add @casoon/fragment-renderer<div class="banner" style="background: #e0f2fe; border-color: #0284c7; color: #0c4a6e;" role="alert" data-astro-cid-sqkjpi7t> <span class="icon" style="background: #0284c7;" data-astro-cid-sqkjpi7t>i </span> <span class="message" data-astro-cid-sqkjpi7t>Important announcement! </span> </div>
- presets: HTMX, email, CMS blocks
- 3
- adapters: Node.js, Cloudflare, Vercel, CLI
- 4
- runtime dependencies besides the Astro peer
- 0
- example components rendered during this site's build
- 4
What it does
Zero config
<code>createAstroRuntime()</code> works without options. Registry, services and presets are there when you need them.
Registry by ID
Map IDs to lazily imported components, with category and tags for filtering. A CMS block type becomes a component lookup.
One component, several channels
A context with <code>locale</code> and <code>channel</code> reaches the component as a prop, so one source can produce web, email or OG markup.
Handlers for the platform
Adapters build the response for Node.js, Cloudflare Workers and Vercel, and write files from a script.
Generated at build time
All examples →<div class="banner" style="background: #e0f2fe; border-color: #0284c7; color: #0c4a6e;" role="alert" data-astro-cid-sqkjpi7t> <span class="icon" style="background: #0284c7;" data-astro-cid-sqkjpi7t>i </span> <span class="message" data-astro-cid-sqkjpi7t>Important announcement! </span> </div>
The Banner component from the repository's examples, rendered by the runtime while this site was built. Markup is indented here for reading only.
examples/cloudflare-worker-demo/src/components/Banner.astroQuickstart
Install the package, render a component, return the result. Registry, presets and adapters are covered in the documentation.
- Install
@casoon/fragment-renderer; Astro is a peer dependency. - Create a runtime and call
renderComponentorrenderToResponse. - Add a registry, a preset or an adapter when the project needs one.
import { createAstroRuntime } from '@casoon/fragment-renderer';
import Banner from './Banner.astro';
const runtime = createAstroRuntime();
const html = await runtime.renderComponent(Banner, {
message: 'Important announcement!',
type: 'info',
});
const response = await runtime.renderToResponse(Banner, { message: 'Saved' });