|
1 | 1 | --- |
2 | 2 | title: The Content Pipeline |
3 | 3 | 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. |
5 | 5 | tags: ssg, architecture, tempura |
6 | 6 | --- |
7 | 7 |
|
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. |
9 | 9 |
|
10 | 10 | ## $pages |
11 | 11 |
|
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: |
13 | 13 |
|
14 | 14 | ```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> |
17 | 17 | {{/each}} |
18 | 18 | ``` |
19 | 19 |
|
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. |
21 | 21 |
|
22 | 22 | ## $section |
23 | 23 |
|
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. |
25 | 25 |
|
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: |
27 | 27 |
|
28 | 28 | ```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> |
32 | 32 | {{/if}} |
33 | 33 | {{/each}} |
34 | 34 | ``` |
35 | 35 |
|
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: |
37 | 37 |
|
38 | 38 | ```hbs |
39 | 39 | {{#var posts = $utils.sortByDate($section)}} |
40 | 40 | ``` |
41 | 41 |
|
42 | 42 | ## $tags |
43 | 43 |
|
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`. |
45 | 45 |
|
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 | +``` |
47 | 52 |
|
48 | 53 | ## The postmeta pattern |
49 | 54 |
|
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: |
51 | 56 |
|
52 | 57 | ```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}} |
54 | 59 | ``` |
55 | 60 |
|
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. |
0 commit comments