From 8a9f12d532660e50a3b39a1c4b5d0295d529f280 Mon Sep 17 00:00:00 2001 From: Spencer Brower <6729162+sbrow@users.noreply.github.com> Date: Mon, 13 Jul 2026 12:14:45 -0400 Subject: [PATCH] fix(content.odin): Replaced eprint calls with log. --- content.odin | 34 +++++++++++++++++++--------------- main.odin | 4 ++++ site.odin | 4 +++- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/content.odin b/content.odin index 7d36194..b5e1ad9 100644 --- a/content.odin +++ b/content.odin @@ -3,6 +3,7 @@ package main import cm "vendor:commonmark" import "core:fmt" +import "core:log" import "core:os" import "core:strings" @@ -29,6 +30,8 @@ Page :: struct { // walk_content reads the content directory and returns all non-draft pages // (or all pages if include_drafts is true). +// +// TODO: What is the lifetime of pages? walk_content :: proc(content_path: string, include_drafts: bool) -> []Page { pages: [dynamic]Page @@ -40,7 +43,9 @@ walk_content :: proc(content_path: string, include_drafts: bool) -> []Page { collect_posts(&pages, posts_path) } - if !include_drafts { + if include_drafts { + return pages[:] + } else { filtered: [dynamic]Page for &page in pages { if !page.draft { @@ -50,8 +55,6 @@ walk_content :: proc(content_path: string, include_drafts: bool) -> []Page { delete(pages) return filtered[:] } - - return pages[:] } collect_home :: proc(pages: ^[dynamic]Page, content_path: string) { @@ -78,7 +81,7 @@ collect_home :: proc(pages: ^[dynamic]Page, content_path: string) { collect_standalone :: proc(pages: ^[dynamic]Page, content_path: string) { entries, err := os.read_all_directory_by_path(content_path, context.allocator) if err != nil { - fmt.eprintfln("thor: cannot read %s: %v", content_path, err) + log.warnf("thor: cannot read %s: %v", content_path, err) return } defer os.file_info_slice_delete(entries, context.allocator) @@ -105,7 +108,7 @@ collect_standalone :: proc(pages: ^[dynamic]Page, content_path: string) { collect_posts :: proc(pages: ^[dynamic]Page, posts_path: string) { entries, err := os.read_all_directory_by_path(posts_path, context.allocator) if err != nil { - fmt.eprintfln("thor: cannot read %s: %v", posts_path, err) + log.warnf("thor: cannot read %s: %v", posts_path, err) return } defer os.file_info_slice_delete(entries, context.allocator) @@ -149,7 +152,7 @@ load_page :: proc( ) { data, err := os.read_entire_file_from_path(file_path, context.allocator) if err != nil { - fmt.eprintfln("thor: cannot read %s: %v", file_path, err) + log.warnf("thor: cannot read %s: %v", file_path, err) return } @@ -159,15 +162,15 @@ load_page :: proc( body = strings.trim_left(content, " \t\r\n") } - page.type = page_type - page.slug = slug - page.title = fm.title + page.type = page_type + page.slug = slug + page.title = fm.title page.description = fm.description - page.date = fm.date - page.draft = fm.draft - page.is_starred = fm.isStarred - page.menu = fm.menu - page.body = strings.clone(body) + page.date = fm.date + page.draft = fm.draft + page.is_starred = fm.isStarred + page.menu = fm.menu + page.body = strings.clone(body) if strings.has_suffix(file_path, ".html") { page.body_html = strings.clone(body) @@ -221,7 +224,8 @@ copy_static_assets :: proc(content_path: string, output_dir: string) { dest := fmt.tprintf("%s/%s", output_dir, entry.name) if err := os.copy_file(dest, entry.fullpath); err != nil { - fmt.eprintfln("thor: cannot copy %s: %v", entry.name, err) + log.warnf("thor: cannot copy %s: %v", entry.name, err) } } } + diff --git a/main.odin b/main.odin index 069ba5f..1e4beba 100644 --- a/main.odin +++ b/main.odin @@ -1,8 +1,12 @@ package main +import "core:log" import "core:os" main :: proc() { + console_logger := log.create_console_logger() + defer log.destroy_console_logger(console_logger) + site: Site init_site(&site, os.args) defer destroy_site(&site) diff --git a/site.odin b/site.odin index a416761..56777e4 100644 --- a/site.odin +++ b/site.odin @@ -3,6 +3,7 @@ package main import "core:encoding/json" import "core:flags" import "core:fmt" +import "core:log" import "core:mem" import "core:os" import "core:strings" @@ -46,6 +47,7 @@ init_site :: proc(site: ^Site, args: []string) { } // Hardcoded defaults (lowest precedence) + // TODO: Probably shouldn't use temp allocator here? if site.content_dir == "" { site.content_dir = fmt.tprintf("%s/content", config_dir) } @@ -74,7 +76,7 @@ load_site_config :: proc( unmarshal_err := json.unmarshal_string(string(data), config, allocator = allocator) if unmarshal_err != nil { - fmt.eprintfln("thor: failed to parse %s: %v", path, unmarshal_err) + log.warnf("thor: failed to parse %s: %v", path, unmarshal_err) return }