From 584da4a4e0fec8873b3168ec5b0002a1bbc1c392 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Tue, 11 Aug 2026 14:28:56 -0500 Subject: Render the table of contents, and group /blog/ by year MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two of the differences the page-by-page diff against the live site turned up. The TOC was the larger one: live has one on 171 pages and the org-ssg build had none. `[html] toc = true` only *exposes* `page.toc` — rendering it is the layout's job, and base.html never did. It now emits the same `div#table-of-contents` Emacs does, from a recursive macro over the tree. The anchors already matched, so every link lands where the live one does. Pages that say `#+OPTIONS: toc:nil` get an empty tree and render nothing, which is why /uses/, /now/ and /salary/ have no TOC here either — the same three as live. /blog/ now breaks its list under year headings, as the live index does, using `page.year` and minijinja's groupby. `group_by_year` at the top of blog.html turns it off for one flat list. After both, /blog/ matches the live page's content exactly, and 171 of 171 TOCs are accounted for. --- content/templates/base.html | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'content/templates/base.html') diff --git a/content/templates/base.html b/content/templates/base.html index 6345700..cfda0f1 100644 --- a/content/templates/base.html +++ b/content/templates/base.html @@ -10,6 +10,27 @@ Available here: page (.title .url .source .date .date_iso .tags .excerpt .toc .keywords), site, nav, root, stylesheet. See the org-ssg guide on Templates. #} +{#- The table of contents, in the shape Emacs exports it. `page.toc` is a tree of + {title, anchor, level, children}, and it is empty when the page has no headings or + says `#+OPTIONS: toc:nil` — so pages that opt out simply render nothing here. #} +{%- macro toc_list(entries) -%} + +{%- endmacro %} +{%- macro toc(entries) -%} +{%- if entries %} +
+

Table of Contents

+
+{{- toc_list(entries) }} +
+
+{%- endif %} +{%- endmacro %} @@ -59,7 +80,9 @@ {%- endif %} {#- Blog posts add a reply footer inside this block; see post.html, which the [[pages]] rule in org-ssg.toml selects for everything under blog/. #} -
{% block content %}{{ body | safe }}{% endblock %}
+
+{{- toc(page.toc) }} +{% block content %}{{ body | safe }}{% endblock %}
{% endblock %} -- cgit v1.2.3