Compare commits
8
Commits
3b1e0cb3f0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da9952c535 | ||
|
|
1b5f806139 | ||
|
|
b34f57c7bb | ||
|
|
29c69243f9 | ||
|
|
445a1d124b | ||
|
|
ae4d04d633 | ||
|
|
8bd86f408a | ||
|
|
53bddab72f |
@@ -2,6 +2,7 @@ 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
|
||||||
|
|||||||
@@ -1,11 +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:mem"
|
import "core:mem"
|
||||||
import "core:os"
|
|
||||||
import "core:strings"
|
|
||||||
import "core:time"
|
import "core:time"
|
||||||
import fleg "flag"
|
import fleg "flag"
|
||||||
|
|
||||||
@@ -16,43 +15,6 @@ import fleg "flag"
|
|||||||
* 4. (write fancy timings and footer for main page)
|
* 4. (write fancy timings and footer for main page)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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){
|
|
||||||
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 = 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>")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
// Arena used for ALL allocations, easier to drop everything at end of execution.
|
// Arena used for ALL allocations, easier to drop everything at end of execution.
|
||||||
arena: vmem.Arena
|
arena: vmem.Arena
|
||||||
@@ -65,7 +27,7 @@ main :: proc() {
|
|||||||
when ODIN_DEBUG {
|
when ODIN_DEBUG {
|
||||||
total_size: int
|
total_size: int
|
||||||
track: mem.Tracking_Allocator
|
track: mem.Tracking_Allocator
|
||||||
mem.tracking_allocator_init(&track, context.allocator)
|
mem.tracking_allocator_init(&track, context.allocator, context.allocator)
|
||||||
context.allocator = mem.tracking_allocator(&track)
|
context.allocator = mem.tracking_allocator(&track)
|
||||||
|
|
||||||
defer {
|
defer {
|
||||||
@@ -88,7 +50,7 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fleg.init_custom_allocator(context.allocator)
|
fleg.init_custom_allocator(context.allocator)
|
||||||
//defer fleg.destroy() //not needede when we free the alloc' anyway
|
//defer fleg.destroy() //not needed when we free the alloc' anyway
|
||||||
|
|
||||||
directory: string
|
directory: string
|
||||||
output_dir: string
|
output_dir: string
|
||||||
@@ -104,29 +66,9 @@ main :: proc() {
|
|||||||
// Walk directory and collect .md files
|
// Walk directory and collect .md files
|
||||||
md_files := walk_tree_and_get_md_names(directory, context.allocator)
|
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)
|
||||||
if file == ".DS_Store" { continue } //Ignore annoying MacOS (TODO: clean up proc?)
|
|
||||||
md_filename := strings.split(file, directory, context.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, context.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, context.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
|
|
||||||
|
|
||||||
defer write_footer_and_timings(trimmed_filename, final_html_file, start, context.allocator)
|
|
||||||
}
|
|
||||||
defer free_all(context.allocator)
|
defer free_all(context.allocator)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -105,7 +105,7 @@ parse_file_md_to_html :: proc(filename: string, allocator := context.allocator,
|
|||||||
|
|
||||||
html := cm.render_html(root, CMARK_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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
GREEN='\033[0;32m'
|
|
||||||
YELLOW='\033[1;33m'
|
|
||||||
CYAN='\033[0;36m'
|
|
||||||
RESET='\033[0m'
|
|
||||||
|
|
||||||
DEBUG=false
|
|
||||||
UPLOAD=false
|
|
||||||
CLEAN=false
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo "Usage: $(basename "$0") [-d] [-u] [-c] [-h]"
|
|
||||||
echo ""
|
|
||||||
echo "Options:"
|
|
||||||
echo " -d Debug build (adds -debug flag to odin)"
|
|
||||||
echo " -u Upload HTML to webserver after build"
|
|
||||||
echo " -c Clean old HTML files before generating"
|
|
||||||
echo " -h Show this help message"
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
while getopts "duch" opt; do
|
|
||||||
case $opt in
|
|
||||||
d) DEBUG=true ;;
|
|
||||||
u) UPLOAD=true ;;
|
|
||||||
c) CLEAN=true ;;
|
|
||||||
h) usage ;;
|
|
||||||
*) usage ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
if $CLEAN; then
|
|
||||||
echo -e "${YELLOW}[INFO]${RESET} Removing old HTML files..."
|
|
||||||
find /Users/simon/website_backup/NEW/HTML -type f -name "*.html" -delete
|
|
||||||
echo -e "${GREEN}[ OK ]${RESET} Old HTML removed"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $DEBUG; then
|
|
||||||
echo -e "${CYAN}[INFO]${RESET} Debug build"
|
|
||||||
odin build . -debug
|
|
||||||
else
|
|
||||||
echo -e "${CYAN}[INFO]${RESET} Release build"
|
|
||||||
odin build . -o:speed
|
|
||||||
fi
|
|
||||||
echo -e "${GREEN}[ OK ]${RESET} Build complete"
|
|
||||||
|
|
||||||
./cm -dir="/Users/simon/website_backup/NEW/" -out="/Users/simon/website_backup/NEW/HTML"
|
|
||||||
echo -e "${GREEN}[ OK ]${RESET} HTML generated"
|
|
||||||
|
|
||||||
if $UPLOAD; then
|
|
||||||
echo -e "${YELLOW}[INFO]${RESET} Uploading to server..."
|
|
||||||
rsync -aP /Users/simon/website_backup/NEW/HTML/* root@www.simonkellet.xyz:/var/www/cabin/
|
|
||||||
echo -e "${GREEN}[ OK ]${RESET} Upload complete"
|
|
||||||
fi
|
|
||||||
Reference in New Issue
Block a user