Skip to content

Commit 42d70c9

Browse files
committed
docs: refresh template posts
The template's posts described an older bongo: dev serving public/ over EventSource, .hbs content without $pages, a map for $tags, raw .ts in the package, and a roadmap of what has since shipped.
1 parent 357b79a commit 42d70c9

9 files changed

Lines changed: 144 additions & 157 deletions

File tree

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
---
22
title: About
3-
summary: About the bongo static site generator — who it's for, design goals, and what it deliberately avoids.
3+
summary: About the bongo static site generator: who it is for, its design goals, and what it leaves out.
44
---
55

66
# About bongo
77

8-
bongo is an experimental static site generator written in TypeScript, powered by [Bun](https://bun.sh), and built for the kind of site that doesn't need a server.
8+
bongo is a static site generator written in TypeScript. It runs in Bun, Deno, and Node, and it is made for sites that need no server.
99

1010
## Who it's for
1111

12-
If you're building a blog, a documentation site, a marketing page, or a portfolio — bongo is a good fit. If you need user authentication, personalised content, or real-time data, you probably want something else (or a static frontend backed by an API).
12+
bongo is a good fit for a blog, a docs site, a marketing page, or a portfolio. If you need sign-in, content for each user, or live data, you probably want something else, or a static site that calls an API.
1313

1414
## Design goals
1515

16-
- **Fast by default** — rolldown and LightningCSS handle bundling natively in Rust; builds are measured in milliseconds
17-
- **Small surface area** — no runtime dependencies in output, no magic conventions to memorise
18-
- **TypeScript-native** — the config is a `.ts` file, plugins are typed, Bun runs everything without a compile step
19-
- **Plugin system** — loaders can transform any file extension into HTML; the markdown plugin is just a loader
16+
- **Fast by default**: Rolldown and LightningCSS bundle in Rust, and a rebuild renders only the pages that a change reaches.
17+
- **Small surface**: few conventions to learn, and no JavaScript in a page unless you add it.
18+
- **TypeScript first**: the config is a `.ts` file, and the config, plugins, and templates are typed.
19+
- **Plugins are config**: a loader turns any file extension into HTML. The Markdown plugin is only a loader.
2020

2121
## Non-goals
2222

23-
bongo deliberately doesn't include:
23+
bongo leaves out:
2424

25-
- A component model or UI framework
26-
- Server-side rendering or edge functions
27-
- A built-in CMS or content API
28-
- Hot module replacement (it's on the roadmap, but not a v1 requirement)
25+
- a component model or a UI framework,
26+
- server-side rendering and edge functions,
27+
- a built-in CMS or content API,
28+
- hot module replacement: dev reloads the page after each rebuild.
2929

3030
## Architecture
3131

32-
The build runs in two passes. Walk 1 scans content, runs loaders, and compiles `.hbs` bodies with limited context. Walk 2 renders layouts with the full page registry — `$pages`, `$section`, `$tags` — available. Assets are bundled in parallel and placeholders are substituted in a final pass.
32+
The build runs in two walks. Walk 1 reads each content file, runs its loaders, and records the page. Then bongo makes the registries: `$pages`, `$section`, and `$tags`. Walk 2 renders `.hbs` content and layouts, which can all read those registries. Last, it bundles the scripts and stylesheets that the pages link, and puts their file names in the pages.
3333

3434
## Source
3535

36-
The source lives on [GitHub](https://github.com/lukeed/bongo). Contributions welcome.
36+
The source is on [GitHub](https://github.com/lukeed/bongo). Contributions are welcome.
Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
11
---
22
title: "The Nested #each Fix in tempura"
33
date: 2026-04-10
4-
summary: "Tracing and fixing a bug where nested #each loops produced incorrect scoped variable bindings in tempura."
5-
tags: tempura, bun, ssg
4+
summary: "How nested #each loops in tempura stopped the outer loop after one pass, and the fix."
5+
tags: tempura, ssg
66
---
77

8-
While building out bongo's blog index layout, we hit a subtle tempura bug: nested `#each` loops were shadowing the outer loop variable in a way that produced garbled output. Here's how we traced it and what the fix looked like.
8+
While we built bongo's blog index layout, we found a bug in tempura: an `#each` inside another `#each` stopped the outer loop after its first item. Here is how we found it, and how we fixed it.
99

1010
## The symptom
1111

1212
A layout like this:
1313

1414
```hbs
15-
{{#each $section as (post)}}
16-
{{#each post.tags as (tag)}}
17-
{{ post.title }} — {{ tag }}
15+
{{#each $section as post}}
16+
{{#each post.tags as tag}}
17+
{{ post.title }}: {{ tag }}
1818
{{/each}}
1919
{{/each}}
2020
```
2121

22-
Would output `{{ post.title }}` as the _inner_ loop's current item instead of the outer `post`. The outer binding was being lost the moment the inner `#each` opened its scope.
22+
printed the tags of the first post only. The other posts were gone.
2323

24-
## Tracing the bug
24+
## The cause
2525

26-
tempura compiles templates to a small intermediate representation before generating output. The scoped variable introduced by `as (name)` is stored in a flat environment object, keyed by name. The bug: when the inner `#each` opened, it _replaced_ the outer binding rather than extending the environment. Closing the inner loop then restored the replaced slot — but the outer variable slot was already gone.
26+
tempura compiles each template to one JavaScript function. Each `#each` became a `for` loop, with its index and its list in `var` names. A `var` belongs to the whole function, not to the loop. So the inner loop wrote over the index and the list of the outer loop. When the inner loop ended, the outer loop saw an index at its end, and stopped.
2727

2828
## The fix
2929

30-
The fix was to make the environment a proper stack. Each `#each` block pushes a new frame; closing the block pops it. Inner bindings shadow outer ones correctly, and the outer binding is restored on pop.
30+
Each loop now declares its names with `let`, which belongs to the loop block alone. An inner loop gets its own index and list, and the outer loop keeps its own:
3131

32-
```ts
33-
// before: flat env object, mutated in place
34-
env[name] = item;
32+
```js
33+
// before: one index and one list for the whole function
34+
for (var i = 0, $$a = list; i < $$a.length; i++) { … }
3535

36-
// after: frame stack, push/pop
37-
env.push({ [name]: item });
38-
// ... render children ...
39-
env.pop();
36+
// after: each loop has its own
37+
for (let i = 0, $$a = list; i < $$a.length; i++) { … }
4038
```
4139

42-
The change was upstreamed to tempura directly rather than worked around in bongo. Fewer than 20 lines changed; all existing tests passed and the new regression test covers the nested case.
43-
44-
## Why this matters for bongo
45-
46-
bongo's blog index layout uses exactly this pattern — iterate `$section`, then within each post iterate `post.tags` for the tag pills. Without the fix, tag rendering was corrupting the post title. The upstream fix means any tempura user benefits, not just bongo.
40+
We fixed it in tempura, not around it in bongo, and added a test for nested loops. Thus every tempura user gets the fix, not only bongo.
Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,61 @@
11
---
22
title: The Content Pipeline
33
date: 2026-03-15
4-
summary: How bongo's $pages, $section, and $tags registries are built, and how to use them effectively in layouts.
4+
summary: What bongo's $pages, $section, and $tags registries hold, and how to use them in templates.
55
tags: ssg, architecture, tempura
66
---
77

8-
After walk 1 completes, bongo has a flat list of compiled pages. Before walk 2 begins, it assembles three registries that layouts can query. Understanding these registries is the key to building index pages, tag clouds, and related-post lists.
8+
After walk 1, bongo knows every page. Before it renders a page, it makes three registries that templates can read. With them you can build index pages, tag lists, and lists of related posts.
99

1010
## $pages
1111

12-
`$pages` is every page on the site, indexed by path. In a layout you can iterate the full list:
12+
`$pages` is a list of every page on the site, sorted by path. Each entry has the `path`, `title`, `summary`, `section`, `tags`, `headings`, and `params` of a page:
1313

1414
```hbs
15-
{{#each $pages as (p)}}
16-
<a href="{{ p.path }}">{{ p.title }}</a>
15+
{{#each $pages as page}}
16+
<a href="{{ page.path }}">{{ page.title }}</a>
1717
{{/each}}
1818
```
1919

20-
This is useful for site maps or global navigation, but usually too broad for section-level features.
20+
It is good for a site map or for global navigation, but it is often too broad for one section.
2121

2222
## $section
2323

24-
`$section` is a filtered subset of `$pages` — only pages whose path shares a directory prefix with the current page. For a page at `/blog/my-post/`, `$section` contains every page under `/blog/`.
24+
`$section` holds the pages in the same folder as the current page. For a page at `content/blog/my-post.md`, it holds every page in `content/blog/`. The index page of the folder and the current page are in it too.
2525

26-
This is the natural way to build a blog index. The layout iterates `$section`, skips the index page itself, and renders a list of posts:
26+
Thus a blog index loops over `$section`, and skips itself:
2727

2828
```hbs
29-
{{#each $section as (p)}}
30-
{{#if p.path !== $page.path}}
31-
<h2><a href="{{ p.path }}">{{ p.title }}</a></h2>
29+
{{#each $section as post}}
30+
{{#if post.path !== $page.path}}
31+
<h2><a href="{{ post.path }}">{{ post.title }}</a></h2>
3232
{{/if}}
3333
{{/each}}
3434
```
3535

36-
`$section` arrives in path-ascending order. To sort by date, pass it through a `$utils` helper:
36+
`$section` is sorted by path. To sort it by date, pass it through a `$utils` helper:
3737

3838
```hbs
3939
{{#var posts = $utils.sortByDate($section)}}
4040
```
4141

4242
## $tags
4343

44-
`$tags` is a map of tag name to array of pages. If any page has `tags: foo, bar` in its frontmatter, `$tags.foo` and `$tags.bar` will each contain that page.
44+
`$tags` has one entry for each tag, as `{ tag, pages }`. The tags come in the order in which they first appear in `$pages`. In frontmatter, `tags` is a list, such as `[ssg, bun]`, or a comma-separated string, such as `ssg, bun`.
4545

46-
Tag values in frontmatter are CSV strings — bongo parses them into a `string[]` on the page object.
46+
```hbs
47+
{{#each $tags as entry}}
48+
<h3>{{ entry.tag }}</h3>
49+
<p>{{ entry.pages.length }} posts</p>
50+
{{/each}}
51+
```
4752

4853
## The postmeta pattern
4954

50-
Because `$page`, `$section`, and `$tags` are only available in layouts (not `.hbs` content bodies), meta like "related posts" must live in a layout or partial. The `postmeta` partial is a good place to put reusable post header markup:
55+
Layouts, partials, and `.hbs` content can all read these values. Put markup that many pages share, such as the date and tags of a post, in a partial:
5156

5257
```hbs
53-
{{#partial src="postmeta" date=$page.params.date tags=$page.tags}}
58+
{{#partial src="postmeta" date=$page.params.date tags=$page.tags draft=$page.draft}}
5459
```
5560

56-
This keeps the single-post layout clean and the meta rendering consistent across the site.
61+
The single-post layout stays short, and each post shows its meta the same way.
Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,28 @@
11
---
2-
title: Dev Server and HMR Readiness
2+
title: The Dev Server
33
date: 2026-03-28
4-
summary: Where bongo's dev server stands today — fast full reload via Bun's HTTP server — and the plan for rolldown HMR.
5-
tags: rolldown, bun, performance
4+
summary: How bongo dev keeps each build in memory, rebuilds only what a change reaches, and reloads the page.
5+
tags: performance, ssg
66
---
77

8-
bongo's dev mode is a work in progress, but it's already useful. Here's where things stand.
8+
`bongo dev` serves the site and builds it again when a file changes. Here is how it works today.
99

10-
## Current implementation
10+
## Output in memory
1111

12-
The dev server is a lightweight Bun HTTP server that serves the `public/` output directory. On each file change, it triggers a full rebuild and sends a reload signal to any open browser tabs via a small injected script and a `EventSource` endpoint.
12+
The dev server keeps each build in memory and serves it from there, as Vite does. It does not write the output folder. Thus `bongo build` can run while `bongo dev` runs, and neither one changes the output of the other. To see the dev output as files, run `bongo dev --write`.
1313

14-
Full rebuild is fast enough to feel acceptable — on the example site, it completes in under 100ms. But it's not HMR.
14+
## Rebuilds
1515

16-
## What rolldown needs for HMR
16+
A rebuild renders only the pages that the change reaches. An edit to one post renders that post, and each page that lists it, such as the blog index. An edit to a layout, a partial, the config, or `data/` renders every page.
1717

18-
True HMR requires the bundler to understand the module graph and emit only the changed modules. rolldown is building toward this: it exposes a stable module graph API and the `hmrUpdate` hook in its Vite-compatible mode.
18+
Dev names each script and stylesheet by its entry, not by its content. So an edit to a stylesheet keeps its file name, and the pages that link it need no new render.
1919

20-
bongo's current bundler integration is a single-shot build (no watch mode). To support HMR we need to:
20+
## Reload
2121

22-
1. Keep rolldown in watch mode between rebuilds
23-
2. Intercept `hmrUpdate` events and forward affected module hashes to the browser
24-
3. On the browser side, accept updates and swap modules without a full page reload
22+
Each open page holds one WebSocket to the dev server. After a good rebuild, the server tells each page to reload. It is a WebSocket, not an event stream: browsers allow only six HTTP/1.1 connections to one host, and an event stream in each open tab blocked page loads.
2523

26-
Step 3 is the hard part for a static site. Unlike a React app, there's no component tree to surgically update. The pragmatic approach — and likely what bongo will ship first — is "fast module invalidation with page scroll preservation": reload the page but restore the scroll position.
24+
When a rebuild fails, the page shows an overlay with the error, and the last good build keeps serving. When a fix builds, the page reloads.
2725

28-
## The injected script
26+
## No HMR yet
2927

30-
Right now, the dev-reload script bongo injects looks roughly like:
31-
32-
```js
33-
const es = new EventSource('/_bongo/reload');
34-
es.onmessage = () => location.reload();
35-
```
36-
37-
It's 2 lines and it works. The production build strips it. When HMR lands, this endpoint will carry module-level update payloads instead.
38-
39-
## Timeline
40-
41-
HMR is behind an open issue. The blocker is rolldown's watch API stabilising — it's available but marked experimental. Once it's stable, wiring it up should be straightforward.
28+
Dev reloads the whole page. It does not swap modules in place. Most pages of a static site load fast, so a full reload is often enough.
Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,54 @@
11
---
22
title: LightningCSS over PostCSS
33
date: 2026-02-20
4-
summary: Why bongo chose LightningCSS over PostCSS for CSS processing, and how CSS modules fit into the story.
4+
summary: Why bongo uses LightningCSS for CSS, and what it does for each stylesheet.
55
tags: lightningcss, performance, ssg
66
---
77

8-
[LightningCSS](https://lightningcss.dev) is a CSS parser, transformer, and bundler written in Rust. bongo uses it to process `assets/*.css` files. Here are some things worth knowing.
8+
[LightningCSS](https://lightningcss.dev) is a CSS parser, transformer, and bundler written in Rust. bongo builds each stylesheet with it. Here are some things worth knowing.
99

10-
## What it does automatically
10+
## Add a stylesheet
1111

12-
LightningCSS handles:
12+
Add a stylesheet to a layout with `<bongo:style>`. The `src` is relative to `assets/`:
1313

14-
- **`@import` inlining** — imported CSS files are merged at build time
15-
- **Vendor prefix injection** — adds `-webkit-`, `-moz-` etc. based on your browser targets
16-
- **Syntax lowering** — modern CSS features are transpiled for older browsers
17-
- **Minification** — dead code removal, property merging, shorthand expansion
14+
```hbs
15+
<bongo:style src="style.css"></bongo:style>
16+
```
17+
18+
bongo writes the built file with a content hash in its name, and links it. With `inline`, it puts the CSS in a `<style>` element instead.
19+
20+
## What it does for you
21+
22+
- **`@import` bundling**: it puts each imported file in the output. An `@import` can also name a package in `node_modules`.
23+
- **Prefixes**: it adds `-webkit-` and other prefixes for your browser target.
24+
- **Syntax lowering**: it turns newer syntax, such as nesting, into syntax that older browsers read.
25+
- **Minification**: with `--minify`, it minifies every stylesheet.
1826

19-
You get all of this without a PostCSS config, a Babel plugin, or a webpack loader.
27+
You need no PostCSS config, no Babel plugin, and no webpack loader.
2028

2129
## Browser targets
2230

23-
Set targets in `bongo.config.ts`:
31+
Set the target in `bongo.config.ts`:
2432

2533
```ts
26-
const config: Config = {
34+
import type { Config } from 'bongo';
35+
36+
export default {
2737
$build: {
28-
target: 'defaults',
38+
target: ['chrome >= 120', 'safari >= 17', 'firefox >= 121'],
2939
},
30-
};
40+
} satisfies Config;
3141
```
3242

33-
Targets follow [browserslist](https://browsersl.ist) syntax. The default is the current browsers if unset.
43+
The target is a [browserslist](https://browsersl.ist) query, or a list of queries. The default is `'defaults'`.
3444

3545
## CSS modules
3646

37-
bongo supports CSS modules via a file naming convention. Name your file `*.module.css` and LightningCSS will scope class names locally. Import the module in your JavaScript to get the scoped names:
38-
39-
```ts
40-
import styles from './button.module.css';
41-
element.className = styles.primary;
42-
```
47+
A file named `*.module.css` is a CSS module: LightningCSS gives its class names a scope, so they do not clash with other stylesheets. To use a `.module.css` file as plain CSS, add `global` to its `<bongo:style>`.
4348

4449
## Custom properties and `@layer`
4550

46-
Custom properties (CSS variables) and `@layer` work out of the box. LightningCSS parses them correctly and minification preserves semantics.
51+
Custom properties and `@layer` work as they are. LightningCSS parses them, and minification keeps what they mean:
4752

4853
```css
4954
@layer base {
@@ -55,6 +60,6 @@ Custom properties (CSS variables) and `@layer` work out of the box. LightningCSS
5560
}
5661
```
5762

58-
## What it doesn't do
63+
## What it does not do
5964

60-
LightningCSS is not PostCSS. It doesn't run PostCSS plugins. If you rely on a specific PostCSS plugin for a feature LightningCSS doesn't support natively, you'll need to run PostCSS as a pre-step outside of bongo.
65+
LightningCSS is not PostCSS, and it does not run PostCSS plugins. If you need a PostCSS plugin for a feature that LightningCSS does not have, run PostCSS as a step before bongo.

0 commit comments

Comments
 (0)