mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
feat: Added -watch flag.
This commit is contained in:
@@ -27,6 +27,10 @@
|
||||
- [ ] `<pre><code>` blocks need to set background to theme background,
|
||||
regardless of prefers-dark. (or use a different theme)
|
||||
- [ ] `-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
|
||||
- [ ] Review every file in thor
|
||||
- [ ] Review alerts.odin
|
||||
|
||||
+9
-3
@@ -32,8 +32,14 @@ Page :: struct {
|
||||
// (or all pages if include_drafts is true).
|
||||
//
|
||||
// TODO: What is the lifetime of pages?
|
||||
walk_content :: proc(content_path: string, include_drafts: bool, sectionate: bool) -> []Page {
|
||||
pages: [dynamic]Page
|
||||
walk_content :: proc(site: ^Site) -> []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_standalone(&pages, content_path, sectionate)
|
||||
@@ -46,7 +52,7 @@ walk_content :: proc(content_path: string, include_drafts: bool, sectionate: boo
|
||||
if include_drafts {
|
||||
return pages[:]
|
||||
} else {
|
||||
filtered: [dynamic]Page
|
||||
filtered := make([dynamic]Page, allocator)
|
||||
for &page in pages {
|
||||
if !page.draft {
|
||||
append(&filtered, page)
|
||||
|
||||
@@ -2,18 +2,28 @@ package main
|
||||
|
||||
import "core:log"
|
||||
import "core:os"
|
||||
import "core:time"
|
||||
|
||||
main :: proc() {
|
||||
console_logger := log.create_console_logger()
|
||||
context.logger = console_logger
|
||||
defer log.destroy_console_logger(console_logger)
|
||||
|
||||
for {
|
||||
defer free_all(context.temp_allocator)
|
||||
site: Site
|
||||
init_site(&site, os.args)
|
||||
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)
|
||||
|
||||
if !site.watch {
|
||||
break
|
||||
}
|
||||
time.sleep(5 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ Site :: struct {
|
||||
params: json.Value,
|
||||
sectionate: bool,
|
||||
drafts: bool `args:"name=drafts"`,
|
||||
watch: bool
|
||||
}
|
||||
|
||||
init_site :: proc(site: ^Site, args: []string) {
|
||||
@@ -98,6 +99,9 @@ site_merge :: proc(config: ^Site, flags: Site) {
|
||||
if flags.drafts {
|
||||
config.drafts = true
|
||||
}
|
||||
if flags.watch {
|
||||
config.watch = true
|
||||
}
|
||||
config.config_path = flags.config_path
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user