From cfb41ef93079a1724ffe910f44c2250990546c97 Mon Sep 17 00:00:00 2001 From: Spencer Brower <6729162+sbrow@users.noreply.github.com> Date: Fri, 17 Jul 2026 11:49:05 -0400 Subject: [PATCH] feat: Improved the template chain. --- render.odin | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/render.odin b/render.odin index 9d54200..2db7bf1 100644 --- a/render.odin +++ b/render.odin @@ -120,24 +120,38 @@ get_template :: proc( layout: string, cache: ^map[string]mustache.Template, ) -> mustache.Template { - if cached, ok := cache[layout]; ok { - return cached + // Build fallback chain: → [section_index] → page → base + chain: [4]string + n := 0 + chain[n] = layout; n += 1 + if strings.has_suffix(layout, "_index") && layout != "section_index" { + chain[n] = "section_index"; n += 1 + } + if layout != "page" && layout != "base" { + chain[n] = "page"; n += 1 + } + if layout != "base" { + chain[n] = "base"; n += 1 } - filename := fmt.tprintf("%s.html", layout) - if os.exists(fmt.tprintf("%s/%s", layouts_dir, filename)) { - tpl := load_template(layouts_dir, filename) - cache[layout] = tpl - return tpl + for i in 0.. string {