From 618e08a7186002181e8b58d65858405cc5cd0fc6 Mon Sep 17 00:00:00 2001 From: Spencer Brower <6729162+sbrow@users.noreply.github.com> Date: Wed, 15 Jul 2026 13:09:47 -0400 Subject: [PATCH] refactor!: replaced `year` with `now.year` in template data. --- TODOS.md | 2 ++ render.odin | 82 ++++++++++++++++++++++++++--------------------------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/TODOS.md b/TODOS.md index d0bc715..1a66650 100644 --- a/TODOS.md +++ b/TODOS.md @@ -24,6 +24,7 @@ guide - [ ] Search for grammars in multiple places - [ ] Download missing grammars. +- [ ] Add reflection support to mustache / consider rewriting from scratch. - [ ] Syntax highlighting in production: CI (`nix build` on ubuntu-latest) has no grammar `.so`s and a machine-specific `QUERIES_PATH` nix store hash, so the deployed site renders unhighlighted. Provide grammars + queries as nix build inputs and pass paths to thor at runtime (env vars/flags). - [ ] Durable highlight paths: read `GRAPHS_PATH`/`QUERIES_PATH` from env vars set by the flake instead of hardcoded nix store hashes, so they survive `nix flake update` and let the grammar/query version-mismatch detector fire automatically. - [ ] Unit tests for highlighting helpers: `capture_name_to_css`, `escape_html`, `unescape_html`, `extract_query_token`, `helix_version_from_path`. @@ -36,6 +37,7 @@ - [ ] Free cmark HTML output (`body_html`) — cmark allocates via C malloc, not the arena, so it leaks per iteration in watch mode - [ ] commands - [ ] Add spall and find ways to reduce run time. (Getting close to 1/2sec here.) +- [ ] warn/error when unknown key used in mustache. - [ ] Review every file in thor - [ ] Review alerts.odin - [ ] Review content.odin diff --git a/render.odin b/render.odin index 5f5547d..a665c3c 100644 --- a/render.odin +++ b/render.odin @@ -139,25 +139,25 @@ render_page_html :: proc(page: Page, config: Site) -> string { is_article := page.type == .Post data := map[string]any { - "title" = fmt.tprintf("%s | %s", page.title, config.title), - "page_title" = page.title, - "body_html" = page.body_html, - "has_date" = page.date != "", - "date_iso" = page.date, - "date_display" = format_date(page.date), - "is_post" = is_article, - "year" = "2026", - "author" = config.author, - "params" = config.params, - "og_url" = fmt.tprintf("%s%s", config.base_url, page.permalink), - "og_site_name" = config.title, - "og_title" = strip_html_tags(page.title), + "title" = fmt.tprintf("%s | %s", page.title, config.title), + "page_title" = page.title, + "body_html" = page.body_html, + "has_date" = page.date != "", + "date_iso" = page.date, + "date_display" = format_date(page.date), + "is_post" = is_article, + "now" = map[string]any{"year" = fmt.tprintf("%d", time.year(time.now()))}, + "author" = config.author, + "params" = config.params, + "og_url" = fmt.tprintf("%s%s", config.base_url, page.permalink), + "og_site_name" = config.title, + "og_title" = strip_html_tags(page.title), "og_description" = config.description, - "og_type" = og_type(is_article), - "is_article" = is_article, - "og_section" = "posts", - "og_published" = page.date, - "og_image" = fmt.tprintf("%s/avatar.jpg", config.base_url), + "og_type" = og_type(is_article), + "is_article" = is_article, + "og_section" = "posts", + "og_published" = page.date, + "og_image" = fmt.tprintf("%s/avatar.jpg", config.base_url), } partials := load_partials(config.layouts_dir) @@ -234,19 +234,19 @@ render_home_html :: proc(home: Page, pages: []Page, config: Site) -> string { } data := map[string]any { - "title" = config.title, - "home_body" = home.body_html, - "list_pages" = list_pages[:], - "year" = "2026", - "author" = config.author, - "params" = config.params, - "og_url" = fmt.tprintf("%s/", config.base_url), - "og_site_name" = config.title, - "og_title" = config.title, + "title" = config.title, + "home_body" = home.body_html, + "list_pages" = list_pages[:], + "now" = map[string]any{"year" = fmt.tprintf("%d", time.year(time.now()))}, + "author" = config.author, + "params" = config.params, + "og_url" = fmt.tprintf("%s/", config.base_url), + "og_site_name" = config.title, + "og_title" = config.title, "og_description" = config.description, - "og_type" = "website", - "is_article" = false, - "og_image" = fmt.tprintf("%s/avatar.jpg", config.base_url), + "og_type" = "website", + "is_article" = false, + "og_image" = fmt.tprintf("%s/avatar.jpg", config.base_url), } partials := load_partials(config.layouts_dir) @@ -292,18 +292,18 @@ render_posts_html :: proc(pages: []Page, config: Site) -> string { } data := map[string]any { - "title" = fmt.tprintf("Posts | %s", config.title), - "year_sections" = year_slices[:], - "year" = "2026", - "author" = config.author, - "params" = config.params, - "og_url" = fmt.tprintf("%s/posts/", config.base_url), - "og_site_name" = config.title, - "og_title" = "Posts", + "title" = fmt.tprintf("Posts | %s", config.title), + "year_sections" = year_slices[:], + "now" = map[string]any{"year" = fmt.tprintf("%d", time.year(time.now()))}, + "author" = config.author, + "params" = config.params, + "og_url" = fmt.tprintf("%s/posts/", config.base_url), + "og_site_name" = config.title, + "og_title" = "Posts", "og_description" = config.description, - "og_type" = "website", - "is_article" = false, - "og_image" = fmt.tprintf("%s/avatar.jpg", config.base_url), + "og_type" = "website", + "is_article" = false, + "og_image" = fmt.tprintf("%s/avatar.jpg", config.base_url), } partials := load_partials(config.layouts_dir)