package main import "core:fmt" import "core:os" import "core:strings" BLOG_START_MD := ` (\ \'\ \'\ __________ / '| ()_________) \ '/ \ ~~~~~~~~ \ \ \ ~~~~~~ \ ==). \__________\ (__) ()__________) ` BLOG_TITLE_MD := ` # Articles and Blogs ` BLOG_BACK_MD := ` [<= Back](./..) ` generate_blog_md_file :: proc(path: string, allocator := context.allocator) { blog_list := make([dynamic]string) sb := strings.builder_make(allocator) blog_md_file := strings.builder_make(allocator) strings.write_string(&sb, path) strings.write_string(&sb, "blog/") blog_dir := strings.to_string(sb) //os.write_string(file, BLOG_START) blogs := walk_tree_and_get_md_names(blog_dir) for blog in blogs { b := strings.split(blog, blog_dir) 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 strings.starts_with(trim_b, "!") {continue} append(&blog_list, blog) } for blog_entry in blog_list { b := strings.split(blog_entry, blog_dir) trim_b := strings.trim_right(b[1], ".md") strings.write_string(&blog_md_file, fmt.aprintf("* [%s](./%s.html)", trim_b, trim_b)) 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), ) } os.write_string(index_file, "```") os.write_string(index_file, BLOG_START_MD) os.write_string(index_file, "```\n") os.write_string(index_file, BLOG_TITLE_MD) os.write_string(index_file, "\n") os.write_string(index_file, strings.to_string(blog_md_file)) os.write_string(index_file, "\n") os.write_string(index_file, BLOG_BACK_MD) }