diff --git a/mustache/pipes_test.odin b/mustache/pipes_test.odin index c952a5f..ff01a66 100644 --- a/mustache/pipes_test.odin +++ b/mustache/pipes_test.odin @@ -207,10 +207,12 @@ test_delete_template_doesnt_leak :: proc(t: ^testing.T) { @(test) test_interp_pipe_basic :: proc(t: ^testing.T) { Scalar_Data :: struct { - name: string, + name: string, + date_format: string, } data := Scalar_Data { name = "2026-03-15T08:49:54-04:00", + date_format = "2 Jan 2006", } tpl, _ := parse("[{{name | format}}]", "", allocator = context.temp_allocator) result, _ := render(tpl, data, {}, context.temp_allocator) @@ -220,10 +222,12 @@ test_interp_pipe_basic :: proc(t: ^testing.T) { @(test) test_interp_pipe_unescaped :: proc(t: ^testing.T) { Scalar_Data :: struct { - name: string, + name: string, + date_format: string, } data := Scalar_Data { name = "2025-12-25T00:00:00Z", + date_format = "2 Jan 2006", } tpl, _ := parse("[{{&name | format}}]", "", allocator = context.temp_allocator) result, _ := render(tpl, data, {}, context.temp_allocator) @@ -233,10 +237,12 @@ test_interp_pipe_unescaped :: proc(t: ^testing.T) { @(test) test_interp_pipe_dot_current :: proc(t: ^testing.T) { List_Data :: struct { - items: [3]string, + items: [3]string, + date_format: string, } data := List_Data { items = {"2026-01-06T00:00:00Z", "2026-06-15T00:00:00Z", "2026-10-15T00:00:00Z"}, + date_format = "2 Jan 2006", } tpl, _ := parse("{{#items}}[{{. | format}}]{{/items}}", "", allocator = context.temp_allocator) result, _ := render(tpl, data, {}, context.temp_allocator) @@ -248,13 +254,15 @@ test_interp_pipe_dot_current :: proc(t: ^testing.T) { // --------------------------------------------------------------------------- Format_Data :: struct { - date: string, + date: string, + date_format: string, } @(test) test_format_typical_iso :: proc(t: ^testing.T) { data := Format_Data { date = "2026-03-15T08:49:54-04:00", + date_format = "2 Jan 2006", } tpl, _ := parse("{{date | format}}", "", allocator = context.temp_allocator) result, _ := render(tpl, data, {}, context.temp_allocator) @@ -265,6 +273,7 @@ test_format_typical_iso :: proc(t: ^testing.T) { test_format_short_date_only :: proc(t: ^testing.T) { data := Format_Data { date = "2026-06-06", + date_format = "2 Jan 2006", } tpl, _ := parse("{{date | format}}", "", allocator = context.temp_allocator) result, _ := render(tpl, data, {}, context.temp_allocator) @@ -275,6 +284,7 @@ test_format_short_date_only :: proc(t: ^testing.T) { test_format_empty_input_errors :: proc(t: ^testing.T) { data := Format_Data { date = "", + date_format = "2 Jan 2006", } tpl, _ := parse("[{{date | format}}]", "", allocator = context.temp_allocator) defer delete_template(&tpl) @@ -286,6 +296,7 @@ test_format_empty_input_errors :: proc(t: ^testing.T) { test_format_non_date_string_errors :: proc(t: ^testing.T) { data := Format_Data { date = "abc", + date_format = "2 Jan 2006", } tpl, _ := parse("[{{date | format}}]", "", allocator = context.temp_allocator) defer delete_template(&tpl) @@ -311,6 +322,7 @@ test_format_non_string_value_errors :: proc(t: ^testing.T) { test_format_invalid_month_errors :: proc(t: ^testing.T) { data := Format_Data { date = "2023-13-15", + date_format = "2 Jan 2006", } tpl, _ := parse("{{date | format}}", "", allocator = context.temp_allocator) defer delete_template(&tpl) @@ -324,6 +336,7 @@ test_format_inside_section_renders :: proc(t: ^testing.T) { // partial uses {{.}} for ISO attr and {{. | format}} for display. data := Format_Data { date = "2025-12-25T00:00:00Z", + date_format = "2 Jan 2006", } tpl, _ := parse( "{{#date}}{{/date}}", @@ -338,6 +351,7 @@ test_format_inside_section_renders :: proc(t: ^testing.T) { test_format_inside_section_skips_when_empty :: proc(t: ^testing.T) { data := Format_Data { date = "", + date_format = "2 Jan 2006", } tpl, _ := parse("[{{#date}}{{/date}}]", "", allocator = context.temp_allocator) result, _ := render(tpl, data, {}, context.temp_allocator) @@ -358,6 +372,7 @@ test_format_handles_all_iso8601_variants :: proc(t: ^testing.T) { for &c in cases { data := Format_Data { date = c.input, + date_format = "2 Jan 2006", } tpl, _ := parse("{{date | format}}", "", allocator = context.temp_allocator) result, _ := render(tpl, data, {}, context.temp_allocator) diff --git a/render.odin b/render.odin index 61a29d6..6501210 100644 --- a/render.odin +++ b/render.odin @@ -25,6 +25,7 @@ Base_Data :: struct { title: string, description: string, og: Open_Graph, + date_format: string, } Page_Data :: struct { @@ -163,6 +164,7 @@ render_site :: proc(site: ^Site) { params = site.params, description = site.description, og = site.og, + date_format = site.date.format, } // Find home page diff --git a/site.odin b/site.odin index 76cffff..0299d98 100644 --- a/site.odin +++ b/site.odin @@ -29,6 +29,12 @@ Site :: struct { features: bit_set[Feature], markdown_extensions: bit_set[md.Extension], og: Open_Graph, + date: Date_Preferences, +} + +Date_Preferences :: struct { + format: string, + timezone: string, } Feature :: enum { @@ -51,6 +57,7 @@ Config_File :: struct { params: json.Value, modules: json.Value, og: Open_Graph, + date: Date_Preferences, } // Configuration loaded from command line arguments. Gets folded in to Site @@ -163,6 +170,7 @@ site_apply_config :: proc(site: ^Site, config: Config_File, config_dir: string) } site.og = config.og + site.date = config.date } site_apply_path_defaults :: proc(site: ^Site, config_dir: string) {