Compare commits
15
Commits
566b44e598
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da9952c535 | ||
|
|
1b5f806139 | ||
|
|
b34f57c7bb | ||
|
|
29c69243f9 | ||
|
|
445a1d124b | ||
|
|
ae4d04d633 | ||
|
|
8bd86f408a | ||
|
|
53bddab72f | ||
|
|
3b1e0cb3f0 | ||
|
|
59d6016296 | ||
|
|
93f0a9a079 | ||
|
|
5c75631c0c | ||
|
|
2cf411327a | ||
|
|
e9c9eefd2b | ||
|
|
f007badc54 |
@@ -2,6 +2,8 @@ cm
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
test/
|
test/
|
||||||
website_update.sh
|
website_update.sh
|
||||||
|
wu.sh
|
||||||
site.png
|
site.png
|
||||||
*.sublime-project
|
*.sublime-project
|
||||||
*.sublime-workspace
|
*.sublime-workspace
|
||||||
|
cm.dSYM/
|
||||||
|
|||||||
@@ -5,6 +5,15 @@ import "core:fmt"
|
|||||||
import "core:os"
|
import "core:os"
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
|
|
||||||
|
/*
|
||||||
|
2026 Simon Kellet
|
||||||
|
Generates the blog index markdown file (blog/index.md) complete with all
|
||||||
|
current blogs/articles. This is then passed to the 'parse_file_md_to_html'
|
||||||
|
We do this to make updating the blog index much easier.
|
||||||
|
|
||||||
|
The final step is to write the blog in order.
|
||||||
|
*/
|
||||||
|
|
||||||
BLOG_START_MD := `
|
BLOG_START_MD := `
|
||||||
(\
|
(\
|
||||||
\'\
|
\'\
|
||||||
@@ -24,13 +33,14 @@ BLOG_BACK_MD := `
|
|||||||
[<= Back](./..)
|
[<= Back](./..)
|
||||||
`
|
`
|
||||||
|
|
||||||
// Generates the blog index markdown file (blog/index.md) complete with all
|
generate_blog_index_md_file :: proc(path: string, allocator := context.allocator) {
|
||||||
// current blogs/articles. This is then passed to the 'parse_file_md_to_html'
|
|
||||||
// We do this to make updating the blog index much easier
|
|
||||||
generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
|
||||||
blog_list := make([dynamic]string, allocator)
|
blog_list := make([dynamic]string, allocator)
|
||||||
|
defer delete(blog_list)
|
||||||
|
|
||||||
sb := strings.builder_make(allocator)
|
sb := strings.builder_make(allocator)
|
||||||
blog_md_file := strings.builder_make(allocator)
|
blog_md_file := strings.builder_make(allocator)
|
||||||
|
defer strings.builder_destroy(&sb)
|
||||||
|
defer strings.builder_destroy(&blog_md_file)
|
||||||
|
|
||||||
strings.write_string(&sb, path)
|
strings.write_string(&sb, path)
|
||||||
strings.write_string(&sb, "blog/")
|
strings.write_string(&sb, "blog/")
|
||||||
@@ -49,6 +59,7 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
|||||||
trim_b := strings.trim_right(b[1], ".md")
|
trim_b := strings.trim_right(b[1], ".md")
|
||||||
|
|
||||||
if trim_b == "index" {continue} //Ignore Index
|
if trim_b == "index" {continue} //Ignore Index
|
||||||
|
if trim_b == ".DS_Store" {continue} //Ignore annoying MacOS files
|
||||||
if strings.starts_with(trim_b, "!") {continue} //Ignore WIP files!
|
if strings.starts_with(trim_b, "!") {continue} //Ignore WIP files!
|
||||||
|
|
||||||
// now add to blog list
|
// now add to blog list
|
||||||
@@ -69,7 +80,7 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
|||||||
free_all(context.temp_allocator)
|
free_all(context.temp_allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sck: Now we create the index.md file.
|
// sck: Now we create the /blog/index.md file.
|
||||||
os.change_directory(blog_dir)
|
os.change_directory(blog_dir)
|
||||||
index_file, err := os.create("index.md")
|
index_file, err := os.create("index.md")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -85,7 +96,7 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
|
|||||||
os.write_string(index_file, "```\n")
|
os.write_string(index_file, "```\n")
|
||||||
os.write_string(index_file, BLOG_TITLE_MD)
|
os.write_string(index_file, BLOG_TITLE_MD)
|
||||||
os.write_string(index_file, "\n")
|
os.write_string(index_file, "\n")
|
||||||
os.write_string(index_file, strings.to_string(blog_md_file))
|
os.write_string(index_file, strings.to_string(blog_md_file)) //CONTENT OF BLOG
|
||||||
os.write_string(index_file, "\n")
|
os.write_string(index_file, "\n")
|
||||||
os.write_string(index_file, BLOG_BACK_MD)
|
os.write_string(index_file, BLOG_BACK_MD)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#+vet explicit-allocators
|
#+vet explicit-allocators
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "base:runtime"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import vmem "core:mem/virtual"
|
import vmem "core:mem/virtual"
|
||||||
import "core:os"
|
import "core:mem"
|
||||||
import "core:strings"
|
|
||||||
import "core:time"
|
import "core:time"
|
||||||
import fleg "flag"
|
import fleg "flag"
|
||||||
|
|
||||||
@@ -21,10 +21,36 @@ main :: proc() {
|
|||||||
arena_err := vmem.arena_init_growing(&arena)
|
arena_err := vmem.arena_init_growing(&arena)
|
||||||
ensure(arena_err == nil)
|
ensure(arena_err == nil)
|
||||||
arena_alloc := vmem.arena_allocator(&arena)
|
arena_alloc := vmem.arena_allocator(&arena)
|
||||||
|
context.allocator = arena_alloc
|
||||||
defer vmem.arena_destroy(&arena) //clean up everything!
|
defer vmem.arena_destroy(&arena) //clean up everything!
|
||||||
|
|
||||||
fleg.init_custom_allocator(arena_alloc) //use arena for flags, why not I made the library!
|
when ODIN_DEBUG {
|
||||||
defer fleg.destroy()
|
total_size: int
|
||||||
|
track: mem.Tracking_Allocator
|
||||||
|
mem.tracking_allocator_init(&track, context.allocator, context.allocator)
|
||||||
|
context.allocator = mem.tracking_allocator(&track)
|
||||||
|
|
||||||
|
defer {
|
||||||
|
if len(track.allocation_map) > 0 {
|
||||||
|
fmt.eprintf("=== %v allocations not freed: ===\n", len(track.allocation_map))
|
||||||
|
for _, entry in track.allocation_map {
|
||||||
|
fmt.eprintf("- %v bytes @ %v\n", entry.size, entry.location)
|
||||||
|
total_size += entry.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(track.bad_free_array) > 0 {
|
||||||
|
fmt.eprintf("=== %v incorrect frees: ===\n", len(track.bad_free_array))
|
||||||
|
for entry in track.bad_free_array {
|
||||||
|
fmt.eprintf("- %p @ %v\n", entry.memory, entry.location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.printfln("[INFO] TOTAL: %v bytes at end of generation!", total_size)
|
||||||
|
mem.tracking_allocator_destroy(&track)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fleg.init_custom_allocator(context.allocator)
|
||||||
|
//defer fleg.destroy() //not needed when we free the alloc' anyway
|
||||||
|
|
||||||
directory: string
|
directory: string
|
||||||
output_dir: string
|
output_dir: string
|
||||||
@@ -34,63 +60,15 @@ main :: proc() {
|
|||||||
|
|
||||||
start := time.tick_now() //start timer for footer
|
start := time.tick_now() //start timer for footer
|
||||||
|
|
||||||
// First generate the blog index file
|
// First generate the blog index MARKDOWN file
|
||||||
generate_blog_md_file(directory, arena_alloc)
|
generate_blog_index_md_file(directory, context.allocator)
|
||||||
|
|
||||||
// Walk directory and collect .md files
|
// Walk directory and collect .md files
|
||||||
md_files := walk_tree_and_get_md_names(directory, arena_alloc)
|
md_files := walk_tree_and_get_md_names(directory, context.allocator)
|
||||||
|
|
||||||
// ************* MAIN LOOP ************
|
// Generate all .md files in .html files
|
||||||
for file, _ in md_files {
|
generate_all_md_files_to_html(md_files, directory, output_dir, start, context.allocator)
|
||||||
// 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!
|
defer free_all(context.allocator)
|
||||||
html, parse_err := parse_file_md_to_html(file, arena_alloc)
|
|
||||||
if parse_err != nil {
|
|
||||||
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")
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
|
|
||||||
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))
|
|
||||||
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
|
|
||||||
|
|
||||||
//Defer this as we want the last page written to have
|
|
||||||
//accurate timings
|
|
||||||
defer {
|
|
||||||
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>")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//TODO: Do timings now?
|
|
||||||
free_all(arena_alloc)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -14,6 +14,7 @@ FAVICON_PREFIX :: "<link rel=\"icon\" type=\"image\\x-icon\" href=\"/imgs/favico
|
|||||||
MASTODON_PREFIX :: "<a rel=me href=https://linuxrocks.online/@simonkellet></a>\n"
|
MASTODON_PREFIX :: "<a rel=me href=https://linuxrocks.online/@simonkellet></a>\n"
|
||||||
HIGHLIGHT_JS_PREFIX :: "<script type=\"text/javascript\" src=\"https://unpkg.com/@highlightjs/cdn-assets@11.11.1/highlight.min.js\"></script>\n<script type=\"text/javascript\" src=\"https://unpkg.com/highlightjs-odinlang@1.4.0/dist/odin.min.js\"></script>\n\n<script type=\"text/javascript\">\n hljs.highlightAll();\n</script>"
|
HIGHLIGHT_JS_PREFIX :: "<script type=\"text/javascript\" src=\"https://unpkg.com/@highlightjs/cdn-assets@11.11.1/highlight.min.js\"></script>\n<script type=\"text/javascript\" src=\"https://unpkg.com/highlightjs-odinlang@1.4.0/dist/odin.min.js\"></script>\n\n<script type=\"text/javascript\">\n hljs.highlightAll();\n</script>"
|
||||||
|
|
||||||
|
CMARK_OPTIONS :: cm.Options{.Unsafe, .Smart}
|
||||||
|
|
||||||
// Write important HTML prefixes to files. This includes:
|
// Write important HTML prefixes to files. This includes:
|
||||||
// - css, utf8, favicon, mastadon and, conditionally, hljs
|
// - css, utf8, favicon, mastadon and, conditionally, hljs
|
||||||
@@ -98,13 +99,13 @@ walk_tree :: proc(path: string) -> []u8 {
|
|||||||
// according to mem's tracking allocator...
|
// according to mem's tracking allocator...
|
||||||
parse_file_md_to_html :: proc(filename: string, allocator := context.allocator, ) -> (parsed: string, err: os.Error) {
|
parse_file_md_to_html :: proc(filename: string, allocator := context.allocator, ) -> (parsed: string, err: os.Error) {
|
||||||
str := os.read_entire_file_from_path(filename, allocator) or_return
|
str := os.read_entire_file_from_path(filename, allocator) or_return
|
||||||
root := cm.parse_document_from_string(string(str), cm.DEFAULT_OPTIONS)
|
root := cm.parse_document_from_string(string(str), CMARK_OPTIONS)
|
||||||
//root := cm.parse_document(raw_data(str), len(str), cm.DEFAULT_OPTIONS)
|
//root := cm.parse_document(raw_data(str), len(str), cm.DEFAULT_OPTIONS)
|
||||||
defer cm.node_free(root)
|
defer cm.node_free(root)
|
||||||
|
|
||||||
html := cm.render_html(root, cm.DEFAULT_OPTIONS)
|
html := cm.render_html(root, CMARK_OPTIONS)
|
||||||
defer cm.free(html)
|
defer cm.free(html)
|
||||||
|
parsed, err = strings.clone_from_cstring(html, allocator)
|
||||||
|
|
||||||
parsed = strings.clone_from_cstring(html, allocator)
|
|
||||||
return parsed, nil
|
return parsed, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
#+vet explicit-allocators
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "core:os"
|
||||||
|
import "core:strings"
|
||||||
|
import "core:time"
|
||||||
|
import "core:fmt"
|
||||||
|
|
||||||
|
create_html_file :: proc(md_f: string, dir: string, output_dir: string, allocater := context.allocator) -> (file: ^os.File, err: os.Error){
|
||||||
|
sb := strings.builder_make(allocater) //sb for writing to files
|
||||||
|
defer strings.builder_destroy(&sb)
|
||||||
|
|
||||||
|
md_filename := strings.split(md_f, dir, allocater)
|
||||||
|
trimmed_filename := strings.trim_right(md_filename[1], ".md")
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
strings.write_string(&sb, fmt.aprintf("%v", trimmed_filename, allocator = allocater))
|
||||||
|
strings.write_string(&sb, ".html")
|
||||||
|
|
||||||
|
//get "full" name for creation + writing to html file
|
||||||
|
full_filename := strings.to_string(sb)
|
||||||
|
file = os.create(full_filename) or_return
|
||||||
|
|
||||||
|
return file, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
write_footer_and_timings :: proc(trimmed_filename: string, file: ^os.File, start: time.Tick, allocator := context.allocator){
|
||||||
|
if trimmed_filename == "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 = allocator))
|
||||||
|
os.write_string(file, fmt.aprintf("in %v ", time.duration_round(end, time.Nanosecond), allocator = allocator))
|
||||||
|
os.write_string(file, "<font color=#ea76cb><3</font> </footer><br>")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_all_md_files_to_html :: proc(md_files: [dynamic]string, directory: string, output_dir: string, start: time.Tick, allocator := context.allocator) {
|
||||||
|
for file, _ in md_files {
|
||||||
|
if file == ".DS_Store" { continue } //Ignore annoying MacOS (TODO: clean up proc?)
|
||||||
|
md_filename := strings.split(file, directory, allocator)
|
||||||
|
trimmed_filename := strings.trim_right(md_filename[1], ".md")
|
||||||
|
// 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_content, parse_err := parse_file_md_to_html(file, allocator)
|
||||||
|
if parse_err != nil {
|
||||||
|
fmt.eprintfln("ERROR: Could not parse file %s: %s", file, os.error_string(parse_err))
|
||||||
|
}
|
||||||
|
|
||||||
|
final_html_file, html_file_err := create_html_file(file, directory, output_dir, allocator)
|
||||||
|
if html_file_err != nil {
|
||||||
|
fmt.eprintfln("ERROR: Could not create file %s: %s", file, os.error_string(html_file_err))
|
||||||
|
}
|
||||||
|
|
||||||
|
write_prefixs_to_html_file(final_html_file)
|
||||||
|
os.write_string(final_html_file, html_content) //WRITE PAGE
|
||||||
|
|
||||||
|
if trimmed_filename == "index"{
|
||||||
|
write_footer_and_timings(trimmed_filename, final_html_file, start, allocator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user