Render individual Yamb posts as view objects with body and preview fragments, a canonical URL and metadata for templates.
For GitHub Packages, route the @yamb scope to https://npm.pkg.github.com and install @yamb/render-html.
Requires Node.js 26.13 or later and yamb 1.1.0 or later. Direct rendering needs no storage.
pnpm add yamb yamb-render-htmlimport { html } from 'yamb-render-html';
const source = {
uri: '2026/11/hello',
title: 'Hello',
text: 'Hello, <world>.'
};
const ctx = {
base: new URL('https://example.com/blog'),
timeZone: 'UTC'
};
const view = await html().post(source, ctx);
console.log(view.url);
console.log(view.body);For Markdown, see the preparation example.
Register renderers: { html: html() } in the Yamb configuration to use post.render('html') or blog.render('html', { post: post.toJSON() }). Collection dispatch fails with YAMB_RENDERER_SCOPE.
html({ prepare }?) and new HtmlRenderer(config?) accept an optional (source, ctx) => PreparedPost | Promise<PreparedPost> callback. Unknown keys fail with YAMB_HTML_RENDERER_CONFIG. The default escapes the body and preview as literal text.
For Markdown and typography, add the preparation stages.
pnpm add yamb-markdown yamb-microtypoimport { markdown } from 'yamb-markdown';
import { microtypo } from 'yamb-microtypo';
import { html } from 'yamb-render-html';
import { prepare } from 'yamb/transform';
await using md = markdown();
await using typo = microtypo();
const stages = [md, md.html(), typo, md.clean()];
const renderer = html({
prepare: (source, ctx) => prepare(source, stages, ctx)
});
const source = {
uri: '2026/11/article',
title: '"An article"',
text: 'Introduction.\n\n---\n\nThe **complete** article.',
preview: 'A separate **summary**.',
cover: {
caption: '"Cover caption"'
}
};
const ctx = {
base: new URL('https://example.com/blog'),
timeZone: 'UTC'
};
const view = await renderer.post(source, ctx);
console.log(view.body);Reuse the Markdown and MicroTypo owners and close them after preparation completes. See Markdown for stage shapes and sanitation and MicroTypo for typography settings.
Direct calls take PostData with a canonical uri, a ctx.base URL and ctx.timeZone. The renderer snapshots the source, validates every field it reads with core’s post schemas and passes the snapshot to prepare; the view keeps its own copy. A live Post fails; pass post.toJSON(). Related IDs resolve in order through ctx.yamb.find(id, { signal }); only current published targets contribute URIs.
| View fields | Value / presence |
|---|---|
uri, slug, status, options |
Captured source values; keys are present even when a direct source omits a value |
url |
Absolute post URL string |
title |
Plain title from the prepared post or source |
body |
Prepared text.html or escaped source text, including the introduction |
preview |
Prepared preview.html or escaped source preview, defaulting to '' |
cover |
Prepared cover, or validated source cover in literal mode; defaults to {} |
tags, author, meta, social |
Captured source values; default to [], {}, {}, {} |
links |
{ related: string[] }, containing resolved published URIs |
createdAt, updatedAt |
UTC instant strings, included when present in the source |
publishedAt, publishedDate |
Included when source publishedAt is present; UTC instant string and YYYY-MM-DD in ctx.timeZone |
View objects own their nested metadata. Read the source ID and Markdown from the Post, and the final HAST from PreparedPost. In lists, use prepared.preview === undefined ? prepared.text.html : prepared.preview.html to preserve an explicitly empty preview.
The renderer passes prepared HTML through to body and preview. A custom prepare must sanitize both fragments. In the Markdown pipeline, run md.clean() after the last HTML-producing stage. Escape plain fields and attribute values in templates.
Source title, text and preview are limited to 500, 1048576 and 5000 UTF-16 units, and a post resolves at most 50 related IDs. Prepared title, body, preview, cover URL, alt and caption each allow 5000000 units. The core cover rules still apply to URL syntax and dimensions.
Invalid source or prepared fields fail with YAMB_RENDERER_INPUT. Direct renderer.post calls propagate callback errors; registered calls use core’s renderer error boundary. Cancellation preserves the native reason.
MIT. See LICENSE.