feat: thor Now searches up the directory tree to find thor.json.

This commit is contained in:
Spencer Brower
2026-07-14 16:08:22 -04:00
parent d1ca36bbd2
commit 3c149246be
2 changed files with 30 additions and 4 deletions
+29 -3
View File
@@ -9,7 +9,8 @@ import "core:os"
import "core:strings"
Site :: struct {
arena: mem.Dynamic_Arena,
// TODO: User can still technically try to set this
arena: mem.Dynamic_Arena `args:"hidden"`,
config_path: string `args:"name=config"`,
title: string,
description: string,
@@ -22,7 +23,7 @@ Site :: struct {
params: json.Value,
sectionate: bool,
drafts: bool `args:"name=drafts"`,
watch: bool
watch: bool,
}
init_site :: proc(site: ^Site, args: []string) {
@@ -33,7 +34,13 @@ init_site :: proc(site: ^Site, args: []string) {
path := _flags.config_path
if path == "" {
path = "./thor.json"
found, ok := find_config("thor.json")
if ok {
path = found
log.debugf("thor: using config %s", path)
} else {
path = "./thor.json"
}
}
if load_site_config(site, path, alloc) {
@@ -120,3 +127,22 @@ destroy_site :: proc(site: ^Site) {
mem.dynamic_arena_destroy(&site.arena)
}
find_config :: proc(filename: string) -> (path: string, ok: bool) {
dir, _ := os.get_working_directory(context.temp_allocator)
for {
candidate := fmt.tprintf("%s/%s", dir, filename)
if os.exists(candidate) {
path = candidate
ok = true
return
}
idx := strings.last_index(dir, "/")
if idx <= 0 {
return
}
dir = dir[:idx]
}
}