added blog index generator
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import "core:fmt"
|
||||
import vmem "core:mem/virtual"
|
||||
import "core:os"
|
||||
import "core:sort"
|
||||
import "core:strings"
|
||||
import "core:time"
|
||||
|
||||
@@ -26,14 +27,14 @@ main :: proc() {
|
||||
arena_alloc := vmem.arena_allocator(&arena)
|
||||
defer vmem.arena_destroy(&arena) //clean
|
||||
|
||||
start := time.tick_now()
|
||||
start := time.tick_now() //start timer for footer
|
||||
|
||||
generate_blog_md_file(directory)
|
||||
|
||||
md_files := walk_tree_and_get_md_names(directory, arena_alloc)
|
||||
end := time.tick_since(start)
|
||||
|
||||
for file, i in md_files {
|
||||
os.change_directory(directory)
|
||||
fmt.printfln("INFO: Parsing %s from .MD to HTML...", file)
|
||||
//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 {
|
||||
@@ -45,24 +46,25 @@ main :: proc() {
|
||||
trimmed_filename := strings.trim_right(filename[1], ".md")
|
||||
//fmt.printfln("INFO: trimmed_filename: %s", trimmed_filename)
|
||||
|
||||
//Change to output directory...
|
||||
os.change_directory(output_dir)
|
||||
|
||||
sb := strings.builder_make(arena_alloc)
|
||||
//print html file name
|
||||
sb := strings.builder_make(arena_alloc) //sb for writing to files, resets ever iteration
|
||||
strings.write_string(&sb, fmt.aprintf("%v", trimmed_filename, allocator = arena_alloc))
|
||||
strings.write_string(&sb, ".html")
|
||||
full_filename := strings.to_string(sb)
|
||||
|
||||
//get "full" name for creation + writing to html file
|
||||
full_filename := strings.to_string(sb)
|
||||
file, file_err := os.create(full_filename)
|
||||
if file_err != nil {
|
||||
fmt.eprintfln("ERROR: Could not open file %s: %s", file, os.error_string(file_err))
|
||||
}
|
||||
|
||||
os.write_string(file, UTF8_PREFIX)
|
||||
os.write_string(file, CSS_PREFIX)
|
||||
os.write_string(file, MASTODON_PREFIX)
|
||||
write_prefixs_to_html_file(file)
|
||||
os.write_string(file, html)
|
||||
|
||||
if trimmed_filename == "index" {
|
||||
switch trimmed_filename {
|
||||
case "index":
|
||||
buf: [1024]u8
|
||||
date := time.now()
|
||||
end := time.tick_since(start)
|
||||
@@ -71,8 +73,9 @@ main :: proc() {
|
||||
os.write_string(file, fmt.aprintf("%s ", time.to_string_dd_mm_yy(date, buf[:])))
|
||||
os.write_string(file, fmt.aprintf("in %v ", time.duration_round(end, time.Nanosecond)))
|
||||
os.write_string(file, "<font color=#ea76cb><3</font> </footer><br>")
|
||||
}
|
||||
|
||||
fmt.printfln("INFO: Wrote %s into HTML!", md_files[i])
|
||||
}
|
||||
//fmt.printfln("INFO: Wrote %s into HTML!", md_files[i])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user