92 lines
2.5 KiB
Odin
92 lines
2.5 KiB
Odin
#+vet explicit-allocators
|
|
package main
|
|
|
|
import "core:fmt"
|
|
import vmem "core:mem/virtual"
|
|
import "core:os"
|
|
import "core:strings"
|
|
import "core:time"
|
|
|
|
print_usage :: proc() {
|
|
fmt.println("Usage:\n\tcm [working dir] [output dir]\nNote:USE FULL PATH!")
|
|
os.exit(0)
|
|
}
|
|
|
|
main :: proc() {
|
|
arena: vmem.Arena
|
|
arena_err := vmem.arena_init_growing(&arena)
|
|
ensure(arena_err == nil)
|
|
arena_alloc := vmem.arena_allocator(&arena)
|
|
defer vmem.arena_destroy(&arena) //clean up everything!
|
|
|
|
if len(os.args) <= 2 || len(os.args) > 3 {
|
|
print_usage()
|
|
return
|
|
}
|
|
|
|
directory := os.args[1]
|
|
output_dir := os.args[2]
|
|
|
|
start := time.tick_now() //start timer for footer
|
|
|
|
generate_blog_md_file(directory, arena_alloc)
|
|
|
|
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 {
|
|
fmt.eprintfln("ERROR: Could not open file %s: %s", file, os.error_string(parse_err))
|
|
}
|
|
|
|
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...
|
|
os.change_directory(output_dir)
|
|
|
|
//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")
|
|
|
|
//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))
|
|
}
|
|
|
|
write_prefixs_to_html_file(file)
|
|
os.write_string(file, html) //WRITE PAGE
|
|
|
|
switch trimmed_filename {
|
|
case "index":
|
|
buf: [1024]u8
|
|
date := time.now()
|
|
end := time.tick_since(start)
|
|
|
|
os.write_string(file, "<br><footer><hr />This site was generated με αγάπη on ")
|
|
os.write_string(
|
|
file,
|
|
fmt.aprintf("%s ", time.to_string_dd_mm_yy(date, buf[:]), allocator = arena_alloc),
|
|
)
|
|
os.write_string(
|
|
file,
|
|
fmt.aprintf(
|
|
"in %v ",
|
|
time.duration_round(end, time.Nanosecond),
|
|
allocator = arena_alloc,
|
|
),
|
|
)
|
|
os.write_string(file, "<font color=#ea76cb><3</font> </footer><br>")
|
|
|
|
}
|
|
}
|
|
|
|
}
|