mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
fix: Replaced eprint calls with log.
This commit is contained in:
+11
-7
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user