From afb98c3bc4cc3ffa6cadb27cf9c25e4de3865759 Mon Sep 17 00:00:00 2001 From: Spencer Brower <6729162+sbrow@users.noreply.github.com> Date: Sun, 2 Aug 2026 15:26:50 -0400 Subject: [PATCH] fix: JSON5 is now supported in frontmatter. --- TODOS.md | 2 +- frontmatter.odin | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/TODOS.md b/TODOS.md index 1d4cbe1..db9eca8 100644 --- a/TODOS.md +++ b/TODOS.md @@ -38,7 +38,7 @@ - [ ] Don't show annoying log output in tests. - [ ] improve home link customization. - [ ] currently an accessibility issue. -- [ ] support JSON5 in in frontmatter +- [x] support JSON5 in in frontmatter - [ ] Create a json schema file for `thor.json`. - [ ] cleanup `#partial switch`es. - [ ] improve json diagnostics. diff --git a/frontmatter.odin b/frontmatter.odin index 1c4970e..e923c18 100644 --- a/frontmatter.odin +++ b/frontmatter.odin @@ -12,7 +12,7 @@ Frontmatter :: struct { publishDate: string, weight: Maybe(int), menus: json.Value, - params: json.Value, + params: json.Value, layout: string, og: Open_Graph, draft: bool, @@ -37,7 +37,7 @@ parse_frontmatter :: proc(content: string) -> (fm: Frontmatter, body: string, ok json_str := content[:end + 1] body = strings.trim_left(content[end + 1:], " \t\r\n") - value, err := json.parse_string(json_str, spec = .JSON) + value, err := json.parse_string(json_str, spec = .JSON5) if err != nil { log.errorf("failed to parse frontmatter JSON: %v", err) return @@ -61,7 +61,7 @@ parse_frontmatter :: proc(content: string) -> (fm: Frontmatter, body: string, ok } fm.layout = json_get_string(obj, "layout") fm.og = json_get_open_graph(obj, "og") - if v, ok := obj["params"]; ok { fm.params = v } + if v, ok := obj["params"]; ok {fm.params = v} ok = true return @@ -117,3 +117,4 @@ json_get_open_graph :: proc(obj: json.Object, key: string) -> Open_Graph { } return og } +