mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
feat: Icons are now loaded from templates (no longer baked-in).
This commit is contained in:
@@ -5,9 +5,9 @@ Thor is a static site generator written in [Odin](https://odin-lang.org), replac
|
||||
## Architecture
|
||||
|
||||
```
|
||||
thor.json ← site config (title, base_url, social, author)
|
||||
thor.json ← site config (title, base_url, author, params)
|
||||
content/ ← markdown and HTML content files
|
||||
layouts/ ← Mustache templates
|
||||
layouts/ ← Mustache templates + partials
|
||||
assets/ ← CSS (TailwindCSS source) and JS
|
||||
public/ ← build output (generated)
|
||||
```
|
||||
@@ -23,11 +23,12 @@ public/ ← build output (generated)
|
||||
| `footnotes.odin` | Footnote definition stripping (pre-cmark) + sidenote injection (post-cmark) |
|
||||
| `alerts.odin` | GitHub alert post-processor (`> [!CAUTION]` → styled blockquote) |
|
||||
| `emoji.odin` | Emoji shortcode expander (`:shrug:` → `¯\_(ツ)_/¯`) |
|
||||
| `render.odin` | Mustache template rendering, all page types, RSS, sitemap, robots.txt |
|
||||
| `render.odin` | Mustache template rendering, all page types, RSS, sitemap, robots.txt, `load_partials` recursive scan |
|
||||
| `feed.odin` | RSS feed + sitemap XML generation |
|
||||
| `icons.odin` | Inline SVG icon constants (home, github, rss, chevron-up, star) |
|
||||
| `mustache/` | Vendored [odin-mustache](https://github.com/benjamindblock/odin-mustache) library |
|
||||
|
||||
Icon SVGs live as HTML partials in `layouts/partials/icons/` (home, github, rss, chevron_up, star).
|
||||
|
||||
### Data flow
|
||||
|
||||
```
|
||||
@@ -38,6 +39,27 @@ content/ → walk_content → []Page (with body_html from cmark pipeline)
|
||||
layouts/*.html → render_site (Mustache render_in_layout) → public/
|
||||
```
|
||||
|
||||
### Config system
|
||||
|
||||
`Site` has `params: json.Value` for arbitrary user-defined data from `thor.json`. Social links and other template-only data live under `"params"`:
|
||||
|
||||
```json
|
||||
{
|
||||
"title": "...",
|
||||
"base_url": "...",
|
||||
"author": "...",
|
||||
"params": {
|
||||
"social": [
|
||||
{ "name": "github", "url": "...", "icon": "icons/github" }
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Templates access params via dotted keys: `{{#params.social}}`, `{{>* icon}}`.
|
||||
|
||||
Config precedence: `CLI flags > thor.json values > hardcoded defaults`.
|
||||
|
||||
### Markdown pipeline (in content.odin `load_page`)
|
||||
|
||||
```
|
||||
@@ -54,24 +76,12 @@ raw markdown
|
||||
### Memory management
|
||||
|
||||
- `Site` owns a `mem.Dynamic_Arena`
|
||||
- `init_site` calls `mem.dynamic_arena_init` before any allocation
|
||||
- `init_site` calls `mem.dynamic_arena_init(&site.arena, alignment = 64)` — the 64-byte alignment is required by Odin's map runtime (`MAP_CACHE_LINE_SIZE`)
|
||||
- Config loading (flags + JSON) uses the arena allocator explicitly
|
||||
- `site_allocator(site)` returns the arena allocator for callers
|
||||
- `destroy_site` frees the arena
|
||||
- **Not yet wired:** `context.allocator` is not set to the arena in `main.odin`, so rendering and content processing still use the heap allocator
|
||||
|
||||
### Config precedence
|
||||
|
||||
```
|
||||
CLI flags > thor.json values > hardcoded defaults
|
||||
```
|
||||
|
||||
`init_site` handles this flow:
|
||||
1. Parse flags into a temp `Site` struct
|
||||
2. Load `thor.json` (if exists)
|
||||
3. `site_merge` — CLI overrides config values
|
||||
4. Hardcoded defaults fill remaining gaps (relative to config file's directory)
|
||||
|
||||
## Building
|
||||
|
||||
### Local development
|
||||
@@ -96,23 +106,29 @@ nix build # runs thor + tailwindcss + cp js, outputs to ./result/
|
||||
```bash
|
||||
cd thor
|
||||
odin test . # site + mustache smoke tests
|
||||
odin test . -all-packages # also runs mustache spec tests
|
||||
odin test mustache # mustache spec + targeted tests (37 total)
|
||||
```
|
||||
|
||||
## Vendored mustache patches
|
||||
|
||||
Two modifications to `mustache/mustache.odin`:
|
||||
Four modifications to `mustache/mustache.odin`:
|
||||
|
||||
1. **`any` unwrapping** in `map_get` and `data_type` — when values come from `map[string]any`, the inner `any` wrapper is unwrapped so type detection works correctly for nested maps and lists.
|
||||
|
||||
2. **Layout partials** — `layout_template.partials = tmpl.partials` added so partials (`{{> nav}}`, `{{> footer}}`) work inside the base layout template.
|
||||
|
||||
3. **Inline partial rendering** — replaced `template_insert_partial` (which injected tokens into the main token list, breaking section iteration) with `template_render_partial` (which lexes the partial, temporarily swaps `tmpl.lexer`, and recursively processes via `template_process_tokens`). Fixes partials inside sections.
|
||||
|
||||
4. **Dynamic Names** — `{{>*key}}` support. When a partial token value starts with `*`, the remaining key is resolved from the data context stack, and the resolved string is used as the partial name. Enables per-item partial selection inside sections (e.g., `{{>* icon}}` resolves `icon` from each social link).
|
||||
|
||||
Extracted `template_process_tokens` from `template_eat_tokens` to separate ROOT initialization + skip pass from the core token loop, allowing partials to reuse the loop.
|
||||
|
||||
## Known limitations
|
||||
|
||||
- Partials inside Mustache sections (`{{#list}}...{{> partial}}...{{/list}}`) produce duplicate items — library token insertion bug. Workaround: inline the markup.
|
||||
- cmark allocates via C malloc, not the arena. HTML output leaks until process exit.
|
||||
- CSS/JS cache busting uses manual `?v=N` query params instead of content hashing.
|
||||
- The `shrug` emoji has a backslash that may not display correctly.
|
||||
- `json.Value` params require 64-byte aligned arena (workaround for `dynamic_arena_allocator_proc` ignoring per-allocation alignment).
|
||||
|
||||
## TODO
|
||||
|
||||
|
||||
Reference in New Issue
Block a user