updated docs
This commit is contained in:
@@ -8,46 +8,58 @@ import "core:strings"
|
||||
import "core:time"
|
||||
import fleg "flag"
|
||||
|
||||
/* Order of operations:
|
||||
* 1. Generate blog/index.md
|
||||
* 2. Parse ALL .md files into .html files
|
||||
* 3. Write HTML prefixes into .hmtl files
|
||||
* 4. (write fancy timings and footer for main page)
|
||||
*/
|
||||
|
||||
main :: proc() {
|
||||
// Arena used for ALL allocations, easier to drop everything at end of execution.
|
||||
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!
|
||||
|
||||
fleg.init_custom_allocator(arena_alloc)
|
||||
fleg.init_custom_allocator(arena_alloc) //use arena for flags, why not I made the library!
|
||||
defer fleg.destroy()
|
||||
|
||||
directory: string
|
||||
output_dir: string
|
||||
|
||||
fleg.StringVar(&directory, "dir", "", "input directory of .MD files", required = true)
|
||||
fleg.StringVar(&output_dir, "out", "", "output directory (html files)", required = true)
|
||||
fleg.parse_flags()
|
||||
|
||||
start := time.tick_now() //start timer for footer
|
||||
|
||||
// First generate the blog index file
|
||||
generate_blog_md_file(directory, arena_alloc)
|
||||
|
||||
// Walk directory and collect .md files
|
||||
md_files := walk_tree_and_get_md_names(directory, arena_alloc)
|
||||
|
||||
// ************* MAIN LOOP ************
|
||||
for file, i in md_files {
|
||||
// sck: I am not sure if changing dir's is needed but I am now relying on it lol
|
||||
os.change_directory(directory)
|
||||
|
||||
// turn all .md files into parsed .html files!
|
||||
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))
|
||||
fmt.eprintfln("ERROR: Could not parse file %s: %s", file, os.error_string(parse_err))
|
||||
}
|
||||
|
||||
filename := strings.split(file, directory, arena_alloc)
|
||||
trimmed_filename := strings.trim_right(filename[1], ".md")
|
||||
|
||||
//Change to output directory. Not sure if this is needed
|
||||
// sck: Change to output directory. Not sure if this also 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
|
||||
sb := strings.builder_make(arena_alloc) //sb for writing to files, resets ever iteration
|
||||
sb := strings.builder_make(arena_alloc) //sb for writing to files
|
||||
defer strings.builder_destroy(&sb)
|
||||
|
||||
strings.write_string(&sb, fmt.aprintf("%v", trimmed_filename, allocator = arena_alloc))
|
||||
@@ -62,6 +74,7 @@ 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 {
|
||||
|
||||
Reference in New Issue
Block a user