now using temp_allocator for string stuff in gen. blog index for mem safety

This commit is contained in:
2026-08-23 14:01:16 +01:00
parent 200d3d376a
commit 21b6dd0b63
+19 -5
View File
@@ -44,19 +44,28 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
// *********** BLOG PARSING ************** // *********** BLOG PARSING **************
for blog in blogs { for blog in blogs {
b := strings.split(blog, blog_dir, allocator) b := strings.split(blog, blog_dir, allocator = context.temp_allocator)
trim_b := strings.trim_right(b[1], ".md") trim_b := strings.trim_right(b[1], ".md")
if trim_b == "index" {continue} //Ignore Index
if trim_b == "index" {continue} //Ignore Index
if strings.starts_with(trim_b, "!") {continue} //Ignore WIP files! if strings.starts_with(trim_b, "!") {continue} //Ignore WIP files!
// now add to blog list
append(&blog_list, blog) append(&blog_list, blog)
free_all(context.temp_allocator)
} }
// sck: note we are doing this in reverse - means the blogs are ordered
// from oldest at the bottom and newest at the top
#reverse for blog_entry in blog_list { #reverse for blog_entry in blog_list {
b := strings.split(blog_entry, blog_dir, allocator) b := strings.split(blog_entry, blog_dir, allocator = context.temp_allocator)
trim_b := strings.trim_right(b[1], ".md") trim_b := strings.trim_right(b[1], ".md")
strings.write_string(&blog_md_file, fmt.aprintf("* [%s](./%s.html)", trim_b, trim_b, allocator = allocator))
strings.write_string(&blog_md_file, fmt.aprintf("* [%s](./%s.html)", trim_b, trim_b, allocator = context.temp_allocator))
strings.write_string(&blog_md_file, "\n") strings.write_string(&blog_md_file, "\n")
free_all(context.temp_allocator)
} }
os.change_directory(blog_dir) os.change_directory(blog_dir)
@@ -64,7 +73,12 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
if err != nil { if err != nil {
fmt.eprintfln("ERROR in generate_blog_md_file: Could not open file %s: %s", index_file, os.error_string(err)) fmt.eprintfln("ERROR in generate_blog_md_file: Could not open file %s: %s", index_file, os.error_string(err))
} }
os.write_string(index_file, "```")
// sck: final step, write everything in the correct order for the index.html page
// note: we generate the MD file for the blog/index.md
// this saves me time from ordering the blog and allows for automagic
// indexing of blogs/articles
os.write_string(index_file, "```text")
os.write_string(index_file, BLOG_START_MD) os.write_string(index_file, BLOG_START_MD)
os.write_string(index_file, "```\n") os.write_string(index_file, "```\n")
os.write_string(index_file, BLOG_TITLE_MD) os.write_string(index_file, BLOG_TITLE_MD)