added fmt and defer
This commit is contained in:
parent
437fe17db0
commit
f96b506abf
19
gen.odin
19
gen.odin
@ -24,7 +24,6 @@ BLOG_BACK_MD := `
|
||||
[<= Back](./..)
|
||||
`
|
||||
generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
||||
|
||||
blog_list := make([dynamic]string, allocator)
|
||||
sb := strings.builder_make(allocator)
|
||||
blog_md_file := strings.builder_make(allocator)
|
||||
@ -39,11 +38,8 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
||||
for blog in blogs {
|
||||
b := strings.split(blog, blog_dir, allocator)
|
||||
trim_b := strings.trim_right(b[1], ".md")
|
||||
if trim_b == "index" {continue}
|
||||
if trim_b == "index_non_blank" {continue}
|
||||
if trim_b == "test" {continue}
|
||||
if trim_b == "test_blog" {continue}
|
||||
if trim_b == "2026-03-16-Test" {continue}
|
||||
if trim_b == "index" { continue } //Ignore Index
|
||||
|
||||
if strings.starts_with(trim_b, "!") { continue }
|
||||
append(&blog_list, blog)
|
||||
}
|
||||
@ -51,21 +47,14 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
||||
for blog_entry in blog_list {
|
||||
b := strings.split(blog_entry, blog_dir, allocator)
|
||||
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 = allocator))
|
||||
strings.write_string(&blog_md_file, "\n")
|
||||
}
|
||||
|
||||
os.change_directory(blog_dir)
|
||||
index_file, err := os.create("index.md")
|
||||
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, "```")
|
||||
os.write_string(index_file, BLOG_START_MD)
|
||||
|
||||
14
main.odin
14
main.odin
@ -34,7 +34,6 @@ main :: proc() {
|
||||
md_files := walk_tree_and_get_md_names(directory, arena_alloc)
|
||||
for file, i in md_files {
|
||||
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)
|
||||
if parse_err != nil {
|
||||
@ -42,11 +41,11 @@ main :: proc() {
|
||||
}
|
||||
|
||||
filename := strings.split(file, directory, arena_alloc)
|
||||
//fmt.printfln("INFO: filename: %s", filename)
|
||||
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)
|
||||
|
||||
//print html file name
|
||||
@ -63,10 +62,11 @@ main :: proc() {
|
||||
|
||||
write_prefixs_to_html_file(file)
|
||||
os.write_string(file, html) //WRITE PAGE
|
||||
|
||||
//Defer this as we want the last page written to have
|
||||
//accurate timings
|
||||
defer {
|
||||
switch trimmed_filename {
|
||||
case "index":
|
||||
defer {
|
||||
buf: [1024]u8
|
||||
date := time.now()
|
||||
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 {
|
||||
|
||||
files := make([dynamic]string, allocator)
|
||||
|
||||
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) {
|
||||
str := os.read_entire_file_from_path(filename, allocator) or_return
|
||||
|
||||
root := cm.parse_document(raw_data(str), len(str), cm.DEFAULT_OPTIONS)
|
||||
defer cm.node_free(root)
|
||||
|
||||
@ -89,6 +87,5 @@ parse_file_md_to_html :: proc(filename: string, allocator := context.allocator)
|
||||
defer cm.free(html)
|
||||
|
||||
parsed = strings.clone_from_cstring(html, allocator)
|
||||
|
||||
return parsed, nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user