tidy up var names/doc + destroy string builders sb and blog_md_file
This commit is contained in:
@@ -5,6 +5,15 @@ import "core:fmt"
|
|||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
|
|
||||||
|
/*
|
||||||
|
2026 Simon Kellet
|
||||||
|
Generates the blog index markdown file (blog/index.md) complete with all
|
||||||
|
current blogs/articles. This is then passed to the 'parse_file_md_to_html'
|
||||||
|
We do this to make updating the blog index much easier.
|
||||||
|
|
||||||
|
The final step is to write the blog in order.
|
||||||
|
*/
|
||||||
|
|
||||||
BLOG_START_MD := `
|
BLOG_START_MD := `
|
||||||
(\
|
(\
|
||||||
\'\
|
\'\
|
||||||
@@ -24,13 +33,14 @@ BLOG_BACK_MD := `
|
|||||||
[<= Back](./..)
|
[<= Back](./..)
|
||||||
`
|
`
|
||||||
|
|
||||||
// Generates the blog index markdown file (blog/index.md) complete with all
|
generate_blog_index_md_file :: proc(path: string, allocator := context.allocator) {
|
||||||
// current blogs/articles. This is then passed to the 'parse_file_md_to_html'
|
|
||||||
// We do this to make updating the blog index much easier
|
|
||||||
generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
|
||||||
blog_list := make([dynamic]string, allocator)
|
blog_list := make([dynamic]string, allocator)
|
||||||
|
defer delete(blog_list)
|
||||||
|
|
||||||
sb := strings.builder_make(allocator)
|
sb := strings.builder_make(allocator)
|
||||||
blog_md_file := strings.builder_make(allocator)
|
blog_md_file := strings.builder_make(allocator)
|
||||||
|
defer strings.builder_destroy(&sb)
|
||||||
|
defer strings.builder_destroy(&blog_md_file)
|
||||||
|
|
||||||
strings.write_string(&sb, path)
|
strings.write_string(&sb, path)
|
||||||
strings.write_string(&sb, "blog/")
|
strings.write_string(&sb, "blog/")
|
||||||
@@ -49,6 +59,7 @@ generate_blog_md_file :: proc(path: string, allocator := context.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 trim_b == ".DS_Store" {continue} //Ignore annoying MacOS files
|
||||||
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
|
// now add to blog list
|
||||||
@@ -69,7 +80,7 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
|||||||
free_all(context.temp_allocator)
|
free_all(context.temp_allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sck: Now we create the index.md file.
|
// sck: Now we create the /blog/index.md file.
|
||||||
os.change_directory(blog_dir)
|
os.change_directory(blog_dir)
|
||||||
index_file, err := os.create("index.md")
|
index_file, err := os.create("index.md")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -85,7 +96,7 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
|||||||
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)
|
||||||
os.write_string(index_file, "\n")
|
os.write_string(index_file, "\n")
|
||||||
os.write_string(index_file, strings.to_string(blog_md_file))
|
os.write_string(index_file, strings.to_string(blog_md_file)) //CONTENT OF BLOG
|
||||||
os.write_string(index_file, "\n")
|
os.write_string(index_file, "\n")
|
||||||
os.write_string(index_file, BLOG_BACK_MD)
|
os.write_string(index_file, BLOG_BACK_MD)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user