My personal blog's source repository.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

70 lines
1.3 KiB

#!/usr/bin/env bash
set -euo pipefail
root=$(dirname "$0")
cd "$root"
export root=$root
blog_sh="$PWD/$(basename $0)"
export blog_name="Aphrodite"
export author="Artémis <me@aphrodite.dev>"
export out_dir="$root/www.aphrodite.dev"
function handle_html {
input="$1/$2.gmi"
tpl_input="$1/$2.tpl"
output="$1/$2.html"
eval $(janet blog.janet --meta $input)
if [[ -x $tpl_input ]]; then
janet blog.janet --html $input | $tpl_input | ./template.html.sh > $output
else
janet blog.janet --html $input | ./template.html.sh > $output
fi
}
function handle_rc {
set +e
input="$1/$2.$3"
output="$1/$2"
$input > $output
if (( $? != 0 )); then
# failed: cleanup
rm -f $output
fi
rm $input
set -e
}
if (( $# == 1 )); then
file="$1"
if [[ ! -f $file ]]; then
>&2 echo "file not found: $file"
exit 1
fi
fpath=$(dirname $file)
fname=$(basename $file)
ext=${fname##*.}
name=${fname%%.$ext}
if [[ "$ext" == "gmi" ]]; then
handle_html $fpath $name
elif [[ "$ext" != "tpl" && -x "$file" ]]; then
handle_rc $fpath $name $ext
fi
exit 0
fi
echo "Initializing..."
if [[ -d "$out_dir" ]]; then
rm -rf "$out_dir"
fi
cp -r files "$out_dir"
echo "Building..."
find "$out_dir" -type f -exec "$blog_sh" {} \;
echo "Cleaning up build..."
find "$out_dir" -name '*.tpl' -delete