fix(content.odin): Replaced eprint calls with log.

This commit is contained in:
Spencer Brower
2026-07-13 12:14:45 -04:00
parent cdb4ad9329
commit 8a9f12d532
3 changed files with 26 additions and 16 deletions
+11 -7
View File
@@ -3,6 +3,7 @@ package main
import cm "vendor:commonmark" import cm "vendor:commonmark"
import "core:fmt" import "core:fmt"
import "core:log"
import "core:os" import "core:os"
import "core:strings" import "core:strings"
@@ -29,6 +30,8 @@ Page :: struct {
// walk_content reads the content directory and returns all non-draft pages // walk_content reads the content directory and returns all non-draft pages
// (or all pages if include_drafts is true). // (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 { walk_content :: proc(content_path: string, include_drafts: bool) -> []Page {
pages: [dynamic]Page pages: [dynamic]Page
@@ -40,7 +43,9 @@ walk_content :: proc(content_path: string, include_drafts: bool) -> []Page {
collect_posts(&pages, posts_path) collect_posts(&pages, posts_path)
} }
if !include_drafts { if include_drafts {
return pages[:]
} else {
filtered: [dynamic]Page filtered: [dynamic]Page
for &page in pages { for &page in pages {
if !page.draft { if !page.draft {
@@ -50,8 +55,6 @@ walk_content :: proc(content_path: string, include_drafts: bool) -> []Page {
delete(pages) delete(pages)
return filtered[:] return filtered[:]
} }
return pages[:]
} }
collect_home :: proc(pages: ^[dynamic]Page, content_path: string) { 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) { collect_standalone :: proc(pages: ^[dynamic]Page, content_path: string) {
entries, err := os.read_all_directory_by_path(content_path, context.allocator) entries, err := os.read_all_directory_by_path(content_path, context.allocator)
if err != nil { if err != nil {
fmt.eprintfln("thor: cannot read %s: %v", content_path, err) log.warnf("thor: cannot read %s: %v", content_path, err)
return return
} }
defer os.file_info_slice_delete(entries, context.allocator) 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) { collect_posts :: proc(pages: ^[dynamic]Page, posts_path: string) {
entries, err := os.read_all_directory_by_path(posts_path, context.allocator) entries, err := os.read_all_directory_by_path(posts_path, context.allocator)
if err != nil { if err != nil {
fmt.eprintfln("thor: cannot read %s: %v", posts_path, err) log.warnf("thor: cannot read %s: %v", posts_path, err)
return return
} }
defer os.file_info_slice_delete(entries, context.allocator) 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) data, err := os.read_entire_file_from_path(file_path, context.allocator)
if err != nil { if err != nil {
fmt.eprintfln("thor: cannot read %s: %v", file_path, err) log.warnf("thor: cannot read %s: %v", file_path, err)
return return
} }
@@ -221,7 +224,8 @@ copy_static_assets :: proc(content_path: string, output_dir: string) {
dest := fmt.tprintf("%s/%s", output_dir, entry.name) dest := fmt.tprintf("%s/%s", output_dir, entry.name)
if err := os.copy_file(dest, entry.fullpath); err != nil { 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)
} }
} }
} }
+4
View File
@@ -1,8 +1,12 @@
package main package main
import "core:log"
import "core:os" import "core:os"
main :: proc() { main :: proc() {
console_logger := log.create_console_logger()
defer log.destroy_console_logger(console_logger)
site: Site site: Site
init_site(&site, os.args) init_site(&site, os.args)
defer destroy_site(&site) defer destroy_site(&site)
+3 -1
View File
@@ -3,6 +3,7 @@ package main
import "core:encoding/json" import "core:encoding/json"
import "core:flags" import "core:flags"
import "core:fmt" import "core:fmt"
import "core:log"
import "core:mem" import "core:mem"
import "core:os" import "core:os"
import "core:strings" import "core:strings"
@@ -46,6 +47,7 @@ init_site :: proc(site: ^Site, args: []string) {
} }
// Hardcoded defaults (lowest precedence) // Hardcoded defaults (lowest precedence)
// TODO: Probably shouldn't use temp allocator here?
if site.content_dir == "" { if site.content_dir == "" {
site.content_dir = fmt.tprintf("%s/content", config_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) unmarshal_err := json.unmarshal_string(string(data), config, allocator = allocator)
if unmarshal_err != nil { 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 return
} }