feat: Added -watch flag.

This commit is contained in:
Spencer Brower
2026-07-14 12:48:38 -04:00
parent f48cc242a4
commit 91606a2223
4 changed files with 32 additions and 8 deletions
+4
View File
@@ -27,6 +27,10 @@
- [ ] `<pre><code>` blocks need to set background to theme background, - [ ] `<pre><code>` blocks need to set background to theme background,
regardless of prefers-dark. (or use a different theme) regardless of prefers-dark. (or use a different theme)
- [ ] `-watch` flag - [ ] `-watch` flag
- [x] basic poll loop
- [ ] filesystem poll loop
- [ ] event based
- [ ] Free cmark HTML output (`body_html`) — cmark allocates via C malloc, not the arena, so it leaks per iteration in watch mode
- [ ] commands - [ ] commands
- [ ] Review every file in thor - [ ] Review every file in thor
- [ ] Review alerts.odin - [ ] Review alerts.odin
+9 -3
View File
@@ -32,8 +32,14 @@ Page :: struct {
// (or all pages if include_drafts is true). // (or all pages if include_drafts is true).
// //
// TODO: What is the lifetime of pages? // TODO: What is the lifetime of pages?
walk_content :: proc(content_path: string, include_drafts: bool, sectionate: bool) -> []Page { walk_content :: proc(site: ^Site) -> []Page {
pages: [dynamic]Page content_path := site.content_dir
include_drafts := site.drafts
sectionate := site.sectionate
allocator := site_allocator(site)
pages := make([dynamic]Page, allocator)
collect_home(&pages, content_path, sectionate) collect_home(&pages, content_path, sectionate)
collect_standalone(&pages, content_path, sectionate) collect_standalone(&pages, content_path, sectionate)
@@ -46,7 +52,7 @@ walk_content :: proc(content_path: string, include_drafts: bool, sectionate: boo
if include_drafts { if include_drafts {
return pages[:] return pages[:]
} else { } else {
filtered: [dynamic]Page filtered := make([dynamic]Page, allocator)
for &page in pages { for &page in pages {
if !page.draft { if !page.draft {
append(&filtered, page) append(&filtered, page)
+12 -2
View File
@@ -2,18 +2,28 @@ package main
import "core:log" import "core:log"
import "core:os" import "core:os"
import "core:time"
main :: proc() { main :: proc() {
console_logger := log.create_console_logger() console_logger := log.create_console_logger()
context.logger = console_logger context.logger = console_logger
defer log.destroy_console_logger(console_logger) defer log.destroy_console_logger(console_logger)
for {
defer free_all(context.temp_allocator)
site: Site site: Site
init_site(&site, os.args) init_site(&site, os.args)
defer destroy_site(&site) defer destroy_site(&site)
// TODO: Make it so this isn't necessary
context.allocator = site_allocator(&site)
pages := walk_content(site.content_dir, site.drafts, site.sectionate) pages := walk_content(&site)
render_site(pages, site) render_site(pages, site)
if !site.watch {
break
}
time.sleep(5 * time.Second)
}
} }
+4
View File
@@ -21,6 +21,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
} }
init_site :: proc(site: ^Site, args: []string) { init_site :: proc(site: ^Site, args: []string) {
@@ -98,6 +99,9 @@ site_merge :: proc(config: ^Site, flags: Site) {
if flags.drafts { if flags.drafts {
config.drafts = true config.drafts = true
} }
if flags.watch {
config.watch = true
}
config.config_path = flags.config_path config.config_path = flags.config_path
} }