This commit is contained in:
Simon Kellet 2026-06-30 13:48:43 +01:00
parent f96b506abf
commit edf62a466f
6 changed files with 1896 additions and 22 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ cm
test/
website_update.sh
site.png
*.sublime-project

1878
cm.sublime-workspace Normal file

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,13 @@ import "core:fmt"
import "core:os"
import "core:strings"
/*
* WIP files are denoted with an '!' at the start of the file.
* This stops the files being processed and uploaded to the site
* before you finish writing!
*/
BLOG_START_MD := `
(\
\'\
@ -40,7 +47,7 @@ generate_blog_md_file :: proc(path: string, allocator := context.allocator) {
trim_b := strings.trim_right(b[1], ".md")
if trim_b == "index" { continue } //Ignore Index
if strings.starts_with(trim_b, "!") { continue }
if strings.starts_with(trim_b, "!") { continue } //Ignore WIP files!
append(&blog_list, blog)
}

View File

@ -9,7 +9,7 @@ import "core:time"
print_usage :: proc() {
fmt.println("Usage:\n\tcm [working dir] [output dir]\nNote:USE FULL PATH!")
os.exit(0)
os.exit(1)
}
main :: proc() {
@ -84,5 +84,6 @@ main :: proc() {
}
}
}
//TODO: Do timings now?
free_all(arena_alloc)
}

View File

@ -1,10 +0,0 @@
{
"character_width": 120,
"tabs": true,
"tabs_width": 4,
"sort_imports": true,
"spaces_around_colons": false,
"align_struct_fields": true,
"align_struct_values": true,
"space_single_line_blocks": true
}

View File

@ -9,11 +9,10 @@ import cm "vendor:commonmark"
MD_SUFFIX :: ".md"
UTF8_PREFIX :: "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n"
CSS_PREFIX :: "<head><link rel=\"stylesheet\" href=\"./css/style.css\">\n"
CSS_PREFIX :: "<head><link rel=\"stylesheet\" href=\"./css/style.css\">\n<title>Simon Kellet</title>"
FAVICON_PREFIX :: "<link rel=\"icon\" type=\"image\\x-icon\" href=\"/imgs/favicon.ico\">\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)
@ -28,25 +27,23 @@ walk_tree_and_get_md_names :: proc(path: string, allocator := context.allocator)
defer os.walker_destroy(&w)
for info in os.walker_walk(&w) {
//handle errors
if path, err := os.walker_error(&w); err != nil {
fmt.eprintfln("failed walking %s: %s", path, err)
continue
}
//Skip a dir
// Skip the Git dir
if strings.has_suffix(info.fullpath, ".git") {
os.walker_skip_dir(&w)
continue
}
if !strings.has_suffix(info.name, MD_SUFFIX) {
continue //skip
}
// Skip files that are NOT .md files
if !strings.has_suffix(info.name, MD_SUFFIX) { continue }
append(&files, strings.clone(info.fullpath, allocator))
}
// Handle error if one happened during iteration at the end:
if path, err := os.walker_error(&w); err != nil {
fmt.eprintfln("failed walking %s: %v", path, err)
@ -67,7 +64,6 @@ walk_tree :: proc(path: string) -> []u8 {
fmt.eprintfln("failed walking %s: %s", path, err)
continue
}
//lets play around
filename = info.name
if !strings.has_suffix(info.name, MD_SUFFIX) {
continue
@ -80,7 +76,8 @@ walk_tree :: proc(path: string) -> []u8 {
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
root := cm.parse_document(raw_data(str), len(str), cm.DEFAULT_OPTIONS)
root := cm.parse_document_from_string(string(str), cm.DEFAULT_OPTIONS)
//root := cm.parse_document(raw_data(str), len(str), cm.DEFAULT_OPTIONS)
defer cm.node_free(root)
html := cm.render_html(root, cm.DEFAULT_OPTIONS)