diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-11-24 12:14:42 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-11-24 12:14:42 +0100 |
| commit | 74d23da9c88e4ec904320d017f81704a78c72e81 (patch) | |
| tree | 801b5075e72f1a362676d592fabc17a62ec4e34e /generate | |
| parent | 992441c88e0b4a75fe4aed0878b5a2c9f4a5180f (diff) | |
| parent | 3ebcd66cd17741ec7dc7793f9f0121e2ee025fdf (diff) | |
| download | cacharle.xyz-74d23da9c88e4ec904320d017f81704a78c72e81.tar.gz cacharle.xyz-74d23da9c88e4ec904320d017f81704a78c72e81.tar.bz2 cacharle.xyz-74d23da9c88e4ec904320d017f81704a78c72e81.zip | |
Merge branch 'templates'
Diffstat (limited to 'generate')
| -rwxr-xr-x | generate | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/generate b/generate new file mode 100755 index 0000000..d13dac6 --- /dev/null +++ b/generate @@ -0,0 +1,72 @@ +#!/bin/sh + +base_template () { + body_file=$(mktemp) + cat > "$body_file" + sed '/<!-- BODY -->/r '"$body_file" base.template.html +} + +base_template_link () { + link_href="$1" + case $link_href in + *.css) + link_rel="stylesheet" + link_type="text/css" + ;; + *.png) + link_rel="icon" + link_type="image/png" + ;; + *) + echo Invalid link file + exit 1 + ;; + esac + sed "/<!-- HEAD -->/i\ + <link rel=\"$link_rel\" type=\"$link_type\" href=\"$link_href\"/>" +} + +# Setup +blog_path=blog +mkdir -p "$blog_path" +base_template < index.template.html | + base_template_link 'favicon.png' | + base_template_link 'style.css' > index.html +base_template < school.template.html | + base_template_link 'favicon.png' | + base_template_link 'style.css' > school.html + +# Generate blog posts +for post_path in "$(find "$blog_path" -name '*.md')" +do + post_dst_path=$(echo "$post_path" | sed 's_.md_.html_') + + pandoc -f markdown -t html < "$post_path" | + base_template | + base_template_link '../favicon.png' | + base_template_link '../style.css' > "$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 + +# Generate utilities +for util_path in utils/* +do + title=$(basename "$util_path" | tr '_' ' ') + sed '$ a <script type="text/javascript" src="script.js"></script>' < "$util_path/index.template.html" | + base_template | + base_template_link '../../favicon.png' | + base_template_link '../../style.css' | + base_template_link 'style.css' > "$util_path/index.html" + sed -i'' "/<!-- UTILSINDEX -->/ a\ + <li><a href=\"$util_path\">$title</a></li>" index.html + + echo "Generated utility at $util_path" +done |
