Appearance
Block examples, catalog and Storybook
Each block of a site can have examples: a Markdown file next to its definition, written exactly as an author writes the block on a page. The engine renders them — HTML is never written by hand — so what you see in the catalog is what a page gets. How to write the blocks themselves is on the SDK docs site: Write a block.
The same examples feed three views:
| View | Where | For |
|---|---|---|
/_dev/blocks | foliwake dev (local and --remote mode) | Developers: a sidebar of every block, the rendered examples of one, their HTML and their problems |
/_foliwake/blocks | The preview site (and foliwake dev) | Authors: each block's name, the Markdown to write and how it looks |
foliwake blocks render | Files in .foliwake/stories/ | Teams that use Storybook or another component workshop |
Write examples
An example file is components/<name>/<name>.example.md, next to <name>.json, <name>.css and <name>.js. Each example starts with a line <!-- example: Title -->; the text before the first one is an introduction:
md
# Note
A short remark next to the text.
<!-- example: Text only -->
:::note
A note needs only text.
:::
<!-- example: With a title {#titled} -->
:::note
### Remember
The title is optional.
:::- An example is everything after its marker line, up to the next one. The marker is an HTML comment, so Markdown viewers hide it and the block content may use headings of any level (also a block whose field is a
##heading). It is rendered like a page of the site (with the site's default dialect fromsite.yaml), so it can hold prose around the block, several blocks, section breaks (---withblocks-v3) and images. {#id}at the end of the marker's title names the example (lowercase letters, digits and-); without it the id is made from the title. Ids are unique in the file: they name the example in the catalog, in the story files and in links such as/_dev/blocks#block-note/titled(or/_dev/blocks/note#note--titledon the block's own page).- A marker is a line of its own; one inside fenced code does not count. A file without markers is one example.
- Images are files in the block folder:
next tonote.example.md. They are site code (committed with the block) and shown as they are, without the responsive variants of content images. - Every example must use its own block. A block without an example file is listed as "No example yet".
Examples are checked like pages: foliwake page check reports their problems with the example file and line, and a code release with an invalid example is refused. foliwake create starts with examples for every block of its templates.
See them while you work: /_dev/blocks
With foliwake dev --watch running, open http://127.0.0.1:3000/_dev/blocks. The page works like Storybook:
- Sidebar: every block by its label, alphabetically, with the number of examples and a red badge for errors; expand a block (or press →) to see its examples. The filter at the top matches block names, labels, example titles and ids: / focuses it, Esc clears it. ↑ ↓ move through the list, ← goes back to the block or collapses it, Enter opens the item. On a phone the sidebar opens with the Blocks button.
- Canvas: one block at a time. Without a selection you see an overview with every block, its examples and its errors.
- Toolbar: the canvas width (full, tablet 768 px, mobile 375 px; drag the corner for any other width), the colour scheme (auto, light, dark) and Open alone, which opens the block's own page.
For the block you pick, you see:
- its label,
:::name, the example file and the number of examples, or a hint to create the file; - each example rendered inside the local page shell — your
styles/styles.css, the block's stylesheets and the loader, which callsinit(root, host)of blocks with JavaScript; - HTML: the engine's output for the example, and Markdown: its source;
- the problems of an invalid example, next to it, with file and line. The other examples still render.
The selection is the address: /_dev/blocks#block-note shows the note, /_dev/blocks#block-note/titled scrolls to its example titled; the older links /_dev/blocks#note--titled still work. Back and forward move between the blocks you looked at.
The canvas is a frame with the block's own page, /_dev/blocks/<name>, which you can also open directly (it is the page to use with the browser console). The frame is why only the chosen block is loaded: the loader of a page starts every block once and never ends them, so the catalog ends the whole frame when you pick another block, and with it that block's listeners, timers, React roots and stylesheets. It also makes the width presets real: your media queries see the canvas width. The colour toggle loads the block page with ?theme=dark or ?theme=light: it sets <html data-theme> (the loader passes it to blocks as host.theme) and switches the prefers-color-scheme rules of your stylesheets; a site without such rules looks the same in every scheme.
With --watch, saving an example, a definition, a stylesheet or a script reloads the catalog and keeps the selection. In --remote mode the block pages are built from your checkout too; nothing is fetched from the hosted site for them.
The catalog for authors: /_foliwake/blocks
When a code release is prepared, the engine renders the examples of that commit into the release (the generated blocks-catalog.json; the example files themselves are not release files). The preview site serves the catalog at /_foliwake/blocks, with the same sidebar, filter, toolbar and links as /_dev/blocks (#block-<name>, #block-<name>/<example>) but without the developer's HTML panels and problems:
- each block's label in the language of the site, then for each example the Markdown to write and how it looks, with the release's own stylesheets and scripts;
/_foliwake/blocks/<name>is the page of one block, which the catalog shows in its canvas; - protected like every preview path: it needs the preview credentials and follows the preview's access rules; the live site never serves it;
- the code release the preview is paired with; a release without examples answers "No block catalog". Branch hosts do not serve it yet.
foliwake dev serves the same page at /_foliwake/blocks from your working files, so you can see what authors will see before you commit.
Storybook
foliwake blocks render writes the examples as files a component workshop can load. The engine does not depend on Storybook and does not install it.
bash
foliwake blocks render # into .foliwake/stories/
foliwake blocks render --watch # and again after every change| File | Contents |
|---|---|
<block>/<example>.html | The engine's HTML of the example |
<block>/<example>.json | block, case, title, html and the css and js files it needs (paths relative to the project) |
<block>.stories.js | A story module for @storybook/html-vite: one story per example, which mounts the HTML, imports the block stylesheets and calls init(root, host, meta) of each block with JavaScript (a page's host, and the block's ui labels) |
_foliwake/block-kit.js, _foliwake/lit-html.js | A copy of block-kit, the engine's module @foliwake/block-kit: blocks import it by that name, which the workshop aliases here (below) |
manifest.json | The index: blocks, their labels and examples, and the files of this run |
Foliwake owns this folder; do not put your own files in it. Every run builds the folder afresh next to it and swaps it in, so anything else inside is removed. During the swap the folder is absent for a moment (Storybook may show an error until the next reload); a run interrupted there is completed by the next run, which puts the previous output back. One run at a time writes a folder: a second blocks render on the same folder (another terminal, or npm run stories twice) is refused while the first runs; the lock .<folder>.lock next to the folder is taken over when its process has ended. A non-empty folder that the command did not write (it has no .foliwake-blocks-render marker) is refused, and so is a folder or parent folder that is a link; then nothing is changed. An invalid example is left out and the command exits with status 1.
Start a project with Storybook
foliwake create asks "Add Storybook for your blocks?" (default: No; --storybook or --no-storybook answers it). With Storybook the project gets .storybook/ and two npm scripts; create does not run npm:
bash
npm install && npm run storiesWith pnpm, pnpm install && pnpm stories works the same. The project has a pnpm-workspace.yaml that approves the install script of esbuild, which Storybook needs: pnpm runs no dependency's install scripts until they are approved, and pnpm 11 stops the install without it (ERR_PNPM_IGNORED_BUILDS). It sets allowBuilds: {esbuild: true} (pnpm 10.26 and later, pnpm 11) and onlyBuiltDependencies: [esbuild] (older pnpm 10); npm and Yarn ignore the file.
npm run stories renders the examples once, keeps them current with --watch and starts Storybook on port 6006. npm run build-stories builds a static Storybook. Blocks with JavaScript run in the stories as on a page, React blocks too: the story calls init(root) without a host, so a block made with foliwake create --react or blocks new --react loads the vendored scripts/vendor/react.js.
Add Storybook to an existing project
Add the packages (exact versions; any recent Storybook 10 works):
bash
npm install --save-dev --save-exact storybook@10.6.3 @storybook/html-vite@10.6.3 vite@8.3.5With pnpm, approve esbuild's install script in pnpm-workspace.yaml first (allowBuilds: with esbuild: true), or run pnpm approve-builds after the install.
.storybook/main.js:
js
import { existsSync, readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
const STORIES = '.foliwake/stories';
const manifest = new URL(`../${STORIES}/manifest.json`, import.meta.url);
if (!existsSync(manifest)) throw new Error('Run `foliwake blocks render` first.');
if (JSON.parse(readFileSync(manifest, 'utf8')).schema !== 'foliwake-block-stories/1') throw new Error('Not a story folder of foliwake blocks render.');
export default {
framework: { name: '@storybook/html-vite', options: {} },
stories: [{ directory: `../${STORIES}`, files: '*.stories.js' }],
// example images in a static build; not in `storybook dev`, where it would shadow the block modules
staticDirs: (dirs = [], { configType } = {}) => (configType === 'PRODUCTION' ? [...dirs, { from: '../components', to: '/components' }] : dirs),
// block-kit: `@foliwake/block-kit` in a block → the copy that `blocks render` writes
// (this replaces other aliases; the main.js of `foliwake create --storybook` keeps them)
viteFinal: (config) => ({
...config,
resolve: { ...config.resolve, alias: [{ find: /^@foliwake\/block-kit$/, replacement: fileURLToPath(new URL(`../${STORIES}/_foliwake/block-kit.js`, import.meta.url)) }] },
}),
};.storybook/preview.js, so every story has the site's own stylesheet:
js
import '../styles/styles.css';
export default { parameters: { layout: 'padded' } };Then run foliwake blocks render --watch and npx storybook dev side by side. Images in the examples are /components/… URLs: the Storybook dev server serves them from the project folder, and staticDirs copies them into a static build (only there: in storybook dev a static /components would be served instead of the transformed block scripts and stylesheets).
