diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-11-09 17:39:05 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-11-09 17:39:05 +0100 |
| commit | 9d2c650d7cadf57ecef3d5a1d39f5f98e298ec64 (patch) | |
| tree | ed33badc6aa8305a5e6ea688a6a08e532c92d268 /generate | |
| parent | f47491b3a89ba769760bb555ea72f1416cb0cb08 (diff) | |
| download | cacharle.xyz-templates.tar.gz cacharle.xyz-templates.tar.bz2 cacharle.xyz-templates.zip | |
Trying to DRY the html with templatestemplates
Diffstat (limited to 'generate')
| -rwxr-xr-x | generate | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/generate b/generate new file mode 100755 index 0000000..725d38e --- /dev/null +++ b/generate @@ -0,0 +1,42 @@ +#!/bin/sh + +# Put your posts in a blog_src directory +# Depends on pandoc for markdown to html convertion + +blog_dir=blog + +[ ! -d "$blog_dir" ] || [ -z "$(ls $blog_dir)" ] && exit 1 +mkdir -p "$blog_dir" + +for post_path in "$blog_dir"/*.md +do + post_dst_path=$(echo "$post_path" | sed 's/\.md/.build.html/') + + # Convert markdown post to html + tmp_file=$(mktemp) + pandoc -f markdown -t html < "$post_path" > "$tmp_file" + + ejs base.ejs -i "{\"pageFilename\": \"$post_path\" }" > "$post_dst_path" + + # Put the blog content in a wrapper template + # sed "/<!--BLOG-->/ r $tmp_file" < blog.template.html > "$post_dst_path" + + # Add blog artcle link to the index.html + title=$(grep '^# .*$' -m 1 "$post_path" | cut -c 2-) + [ -z "$title" ] && echo "post $post_path doesn't have a title" && title=$post_path + + sed -i'' "/<!--BLOGINDEX-->/ a\ + <li><a href=\"$post_dst_path\">$title</a></li>" index.html + + echo "Generated post at $post_dst_path" +done + +for util_path in utils/* +do + title=$(basename "$util_path" | tr '_' ' ') + + ejs base.ejs -i "{\"pageFilename\": \"$post_path\" }" > "$post_dst_path" + + sed -i'' "/<!--UTILSINDEX-->/ a\ + <li><a href=\"$util_path\">$title</a></li>" index.html +done |
