mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
feat: thor Now searches up the directory tree to find thor.json.
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
- [x] OpenGraph meta tags
|
- [x] OpenGraph meta tags
|
||||||
- [x] copy all files from `static` to `public`.
|
- [x] copy all files from `static` to `public`.
|
||||||
- [ ] ensure sidenote numbers render in display order and not in declaration order.
|
- [ ] ensure sidenote numbers render in display order and not in declaration order.
|
||||||
- [ ] Search up for `thor.json` files.
|
- [x] Search up for `thor.json` files.
|
||||||
- [ ] OpenGraph meta tags — verify all fields match production site
|
- [ ] OpenGraph meta tags — verify all fields match production site
|
||||||
- [ ] Table of contents support.
|
- [ ] Table of contents support.
|
||||||
- [ ] Nav items should be active when the current page is selected.
|
- [ ] Nav items should be active when the current page is selected.
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import "core:os"
|
|||||||
import "core:strings"
|
import "core:strings"
|
||||||
|
|
||||||
Site :: struct {
|
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"`,
|
config_path: string `args:"name=config"`,
|
||||||
title: string,
|
title: string,
|
||||||
description: string,
|
description: string,
|
||||||
@@ -22,7 +23,7 @@ Site :: struct {
|
|||||||
params: json.Value,
|
params: json.Value,
|
||||||
sectionate: bool,
|
sectionate: bool,
|
||||||
drafts: bool `args:"name=drafts"`,
|
drafts: bool `args:"name=drafts"`,
|
||||||
watch: bool
|
watch: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
init_site :: proc(site: ^Site, args: []string) {
|
init_site :: proc(site: ^Site, args: []string) {
|
||||||
@@ -33,8 +34,14 @@ init_site :: proc(site: ^Site, args: []string) {
|
|||||||
|
|
||||||
path := _flags.config_path
|
path := _flags.config_path
|
||||||
if path == "" {
|
if path == "" {
|
||||||
|
found, ok := find_config("thor.json")
|
||||||
|
if ok {
|
||||||
|
path = found
|
||||||
|
log.debugf("thor: using config %s", path)
|
||||||
|
} else {
|
||||||
path = "./thor.json"
|
path = "./thor.json"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if load_site_config(site, path, alloc) {
|
if load_site_config(site, path, alloc) {
|
||||||
site_merge(site, _flags)
|
site_merge(site, _flags)
|
||||||
@@ -120,3 +127,22 @@ destroy_site :: proc(site: ^Site) {
|
|||||||
mem.dynamic_arena_destroy(&site.arena)
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user