Compare commits
No commits in common. "d83fc3f75a0c53e4c4997ac9380f4f264c063e2e" and "440562df8bd421a4dbb80c7f633e4b903d29ac9d" have entirely different histories.
d83fc3f75a
...
440562df8b
73
gen.odin
73
gen.odin
@ -1,73 +0,0 @@
|
|||||||
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}
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
29
main.odin
29
main.odin
@ -3,7 +3,6 @@ package main
|
|||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import vmem "core:mem/virtual"
|
import vmem "core:mem/virtual"
|
||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:sort"
|
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
import "core:time"
|
import "core:time"
|
||||||
|
|
||||||
@ -27,14 +26,14 @@ main :: proc() {
|
|||||||
arena_alloc := vmem.arena_allocator(&arena)
|
arena_alloc := vmem.arena_allocator(&arena)
|
||||||
defer vmem.arena_destroy(&arena) //clean
|
defer vmem.arena_destroy(&arena) //clean
|
||||||
|
|
||||||
start := time.tick_now() //start timer for footer
|
start := time.tick_now()
|
||||||
|
|
||||||
generate_blog_md_file(directory)
|
|
||||||
|
|
||||||
md_files := walk_tree_and_get_md_names(directory, arena_alloc)
|
md_files := walk_tree_and_get_md_names(directory, arena_alloc)
|
||||||
|
end := time.tick_since(start)
|
||||||
|
|
||||||
for file, i in md_files {
|
for file, i in md_files {
|
||||||
os.change_directory(directory)
|
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)
|
html, parse_err := parse_file_md_to_html(file, arena_alloc)
|
||||||
if parse_err != nil {
|
if parse_err != nil {
|
||||||
@ -46,25 +45,24 @@ main :: proc() {
|
|||||||
trimmed_filename := strings.trim_right(filename[1], ".md")
|
trimmed_filename := strings.trim_right(filename[1], ".md")
|
||||||
//fmt.printfln("INFO: trimmed_filename: %s", trimmed_filename)
|
//fmt.printfln("INFO: trimmed_filename: %s", trimmed_filename)
|
||||||
|
|
||||||
//Change to output directory...
|
|
||||||
os.change_directory(output_dir)
|
os.change_directory(output_dir)
|
||||||
|
|
||||||
//print html file name
|
sb := strings.builder_make(arena_alloc)
|
||||||
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, fmt.aprintf("%v", trimmed_filename, allocator = arena_alloc))
|
||||||
strings.write_string(&sb, ".html")
|
strings.write_string(&sb, ".html")
|
||||||
|
|
||||||
//get "full" name for creation + writing to html file
|
|
||||||
full_filename := strings.to_string(sb)
|
full_filename := strings.to_string(sb)
|
||||||
|
|
||||||
file, file_err := os.create(full_filename)
|
file, file_err := os.create(full_filename)
|
||||||
if file_err != nil {
|
if file_err != nil {
|
||||||
fmt.eprintfln("ERROR: Could not open file %s: %s", file, os.error_string(file_err))
|
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, UTF8_PREFIX)
|
||||||
|
os.write_string(file, CSS_PREFIX)
|
||||||
|
os.write_string(file, MASTODON_PREFIX)
|
||||||
os.write_string(file, html)
|
os.write_string(file, html)
|
||||||
|
|
||||||
switch trimmed_filename {
|
if trimmed_filename == "index" {
|
||||||
case "index":
|
|
||||||
buf: [1024]u8
|
buf: [1024]u8
|
||||||
date := time.now()
|
date := time.now()
|
||||||
end := time.tick_since(start)
|
end := time.tick_since(start)
|
||||||
@ -73,9 +71,8 @@ main :: proc() {
|
|||||||
os.write_string(file, fmt.aprintf("%s ", time.to_string_dd_mm_yy(date, buf[:])))
|
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, fmt.aprintf("in %v ", time.duration_round(end, time.Nanosecond)))
|
||||||
os.write_string(file, "<font color=#ea76cb><3</font> </footer><br>")
|
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])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,12 +12,6 @@ CSS_PREFIX :: "<head><link rel=\"stylesheet\" href=\"./css/style.css\">\n"
|
|||||||
MASTODON_PREFIX :: "<a rel=me href=https://linuxrocks.online/@simonkellet></a>\n"
|
MASTODON_PREFIX :: "<a rel=me href=https://linuxrocks.online/@simonkellet></a>\n"
|
||||||
|
|
||||||
|
|
||||||
write_prefixs_to_html_file :: proc(file: ^os.File) {
|
|
||||||
os.write_string(file, UTF8_PREFIX)
|
|
||||||
os.write_string(file, CSS_PREFIX)
|
|
||||||
os.write_string(file, MASTODON_PREFIX)
|
|
||||||
}
|
|
||||||
|
|
||||||
walk_tree_and_get_md_names :: proc(
|
walk_tree_and_get_md_names :: proc(
|
||||||
path: string,
|
path: string,
|
||||||
allocator := context.allocator,
|
allocator := context.allocator,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user