added fmt and defer
This commit is contained in:
parent
437fe17db0
commit
f96b506abf
21
gen.odin
21
gen.odin
@ -24,7 +24,6 @@ BLOG_BACK_MD := `
|
|||||||
[<= Back](./..)
|
[<= Back](./..)
|
||||||
`
|
`
|
||||||
generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
||||||
|
|
||||||
blog_list := make([dynamic]string, allocator)
|
blog_list := make([dynamic]string, allocator)
|
||||||
sb := strings.builder_make(allocator)
|
sb := strings.builder_make(allocator)
|
||||||
blog_md_file := strings.builder_make(allocator)
|
blog_md_file := strings.builder_make(allocator)
|
||||||
@ -39,33 +38,23 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
|||||||
for blog in blogs {
|
for blog in blogs {
|
||||||
b := strings.split(blog, blog_dir, allocator)
|
b := strings.split(blog, blog_dir, allocator)
|
||||||
trim_b := strings.trim_right(b[1], ".md")
|
trim_b := strings.trim_right(b[1], ".md")
|
||||||
if trim_b == "index" {continue}
|
if trim_b == "index" { continue } //Ignore Index
|
||||||
if trim_b == "index_non_blank" {continue}
|
|
||||||
if trim_b == "test" {continue}
|
if strings.starts_with(trim_b, "!") { continue }
|
||||||
if trim_b == "test_blog" {continue}
|
|
||||||
if trim_b == "2026-03-16-Test" {continue}
|
|
||||||
if strings.starts_with(trim_b, "!") {continue}
|
|
||||||
append(&blog_list, blog)
|
append(&blog_list, blog)
|
||||||
}
|
}
|
||||||
|
|
||||||
for blog_entry in blog_list {
|
for blog_entry in blog_list {
|
||||||
b := strings.split(blog_entry, blog_dir, allocator)
|
b := strings.split(blog_entry, blog_dir, allocator)
|
||||||
trim_b := strings.trim_right(b[1], ".md")
|
trim_b := strings.trim_right(b[1], ".md")
|
||||||
strings.write_string(
|
strings.write_string(&blog_md_file, fmt.aprintf("* [%s](./%s.html)", trim_b, trim_b, allocator = allocator))
|
||||||
&blog_md_file,
|
|
||||||
fmt.aprintf("* [%s](./%s.html)", trim_b, trim_b, allocator = allocator),
|
|
||||||
)
|
|
||||||
strings.write_string(&blog_md_file, "\n")
|
strings.write_string(&blog_md_file, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
fmt.eprintfln(
|
fmt.eprintfln("ERROR in generate_blog_md_file: Could not open file %s: %s", index_file, os.error_string(err))
|
||||||
"ERROR in generate_blog_md_file: Could not open file %s: %s",
|
|
||||||
index_file,
|
|
||||||
os.error_string(err),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
os.write_string(index_file, "```")
|
os.write_string(index_file, "```")
|
||||||
os.write_string(index_file, BLOG_START_MD)
|
os.write_string(index_file, BLOG_START_MD)
|
||||||
|
|||||||
18
main.odin
18
main.odin
@ -34,7 +34,6 @@ main :: proc() {
|
|||||||
md_files := walk_tree_and_get_md_names(directory, arena_alloc)
|
md_files := walk_tree_and_get_md_names(directory, arena_alloc)
|
||||||
for file, i in md_files {
|
for file, i in md_files {
|
||||||
os.change_directory(directory)
|
os.change_directory(directory)
|
||||||
//fmt.printfln("INFO: Parsing %s from .MD to HTML...", file)
|
|
||||||
|
|
||||||
html, parse_err := parse_file_md_to_html(file, arena_alloc)
|
html, parse_err := parse_file_md_to_html(file, arena_alloc)
|
||||||
if parse_err != nil {
|
if parse_err != nil {
|
||||||
@ -42,11 +41,11 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filename := strings.split(file, directory, arena_alloc)
|
filename := strings.split(file, directory, arena_alloc)
|
||||||
//fmt.printfln("INFO: filename: %s", filename)
|
|
||||||
trimmed_filename := strings.trim_right(filename[1], ".md")
|
trimmed_filename := strings.trim_right(filename[1], ".md")
|
||||||
//fmt.printfln("INFO: trimmed_filename: %s", trimmed_filename)
|
|
||||||
|
|
||||||
//Change to output directory...
|
//Change to output directory. Not sure if this is needed
|
||||||
|
//But messing around with it means I create a lot of
|
||||||
|
//files to clean up. Works for now!
|
||||||
os.change_directory(output_dir)
|
os.change_directory(output_dir)
|
||||||
|
|
||||||
//print html file name
|
//print html file name
|
||||||
@ -63,10 +62,11 @@ main :: proc() {
|
|||||||
|
|
||||||
write_prefixs_to_html_file(file)
|
write_prefixs_to_html_file(file)
|
||||||
os.write_string(file, html) //WRITE PAGE
|
os.write_string(file, html) //WRITE PAGE
|
||||||
|
//Defer this as we want the last page written to have
|
||||||
switch trimmed_filename {
|
//accurate timings
|
||||||
case "index":
|
defer {
|
||||||
defer {
|
switch trimmed_filename {
|
||||||
|
case "index":
|
||||||
buf: [1024]u8
|
buf: [1024]u8
|
||||||
date := time.now()
|
date := time.now()
|
||||||
end := time.tick_since(start)
|
end := time.tick_since(start)
|
||||||
@ -84,5 +84,5 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free_all(arena_alloc)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,6 @@ write_prefixs_to_html_file :: proc(file: ^os.File) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
walk_tree_and_get_md_names :: proc(path: string, allocator := context.allocator) -> [dynamic]string {
|
walk_tree_and_get_md_names :: proc(path: string, allocator := context.allocator) -> [dynamic]string {
|
||||||
|
|
||||||
files := make([dynamic]string, allocator)
|
files := make([dynamic]string, allocator)
|
||||||
|
|
||||||
w := os.walker_create(path)
|
w := os.walker_create(path)
|
||||||
@ -81,7 +80,6 @@ walk_tree :: proc(path: string) -> []u8 {
|
|||||||
|
|
||||||
parse_file_md_to_html :: proc(filename: string, allocator := context.allocator) -> (parsed: string, err: os.Error) {
|
parse_file_md_to_html :: proc(filename: string, allocator := context.allocator) -> (parsed: string, err: os.Error) {
|
||||||
str := os.read_entire_file_from_path(filename, allocator) or_return
|
str := os.read_entire_file_from_path(filename, allocator) or_return
|
||||||
|
|
||||||
root := cm.parse_document(raw_data(str), len(str), cm.DEFAULT_OPTIONS)
|
root := cm.parse_document(raw_data(str), len(str), cm.DEFAULT_OPTIONS)
|
||||||
defer cm.node_free(root)
|
defer cm.node_free(root)
|
||||||
|
|
||||||
@ -89,6 +87,5 @@ parse_file_md_to_html :: proc(filename: string, allocator := context.allocator)
|
|||||||
defer cm.free(html)
|
defer cm.free(html)
|
||||||
|
|
||||||
parsed = strings.clone_from_cstring(html, allocator)
|
parsed = strings.clone_from_cstring(html, allocator)
|
||||||
|
|
||||||
return parsed, nil
|
return parsed, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user