#!/bin/sh TEMPLATEPAGE="./templates/page.html" TEMPLATEBLOG="./templates/blog.html" TEMPLATEATOM="./templates/atom.xml" CONTENTPAGE="./content/page" CONTENTBLOG="./content/blog" OUTPUTDIR="./output" STATIC="./static" # Create necessary directories mkdir -p templates content/page content/blog static rm -rf "$OUTPUTDIR" mkdir -p "$OUTPUTDIR" # Copy static files cp -r "$STATIC"/* "$OUTPUTDIR" # Generate the index page sed '/{{.Content}}/ { r ./content/index.html d }' "$TEMPLATEPAGE" > "$OUTPUTDIR/index.html" # Generate content pages for file in "$CONTENTPAGE"/*.html; do name=$(basename -s .html "$file") mkdir -p "$OUTPUTDIR/$name/" sed '/{{.Content}}/ { r '"$file"' d }' "$TEMPLATEPAGE" > "$OUTPUTDIR/$name/index.html" done # Generate blog posts (only if 'post' is passed as argument) if [ "$1" = "post" ]; then mkdir -p tmp for file in "$CONTENTBLOG"/*.html; do name=$(basename -s .html "$file") mkdir -p "$OUTPUTDIR/blog/$name/" sed '/{{.Content}}/ { r '"$file"' d }' "$TEMPLATEBLOG" > "$OUTPUTDIR/blog/$name/index.html" # Metadata post_date=$(sed -n 's//\1/p' "$file") title=$(sed -n 's//\1/p' "$file") domain=$(sed -n 's//\1/p' "$file") # Append to atom entry list { echo " " echo " $title" echo " " echo " https://$domain/blog/$name/" echo " $post_date" echo " " echo "
" echo " $(cat "$file" | sed '//d' | sed 's/^/ /')" echo "
" echo "
" echo "
" echo "" } >> tmp/entry.xml done # Generate atom with entries injected sed '/{{.Content}}/ { r tmp/entry.xml d }' "$TEMPLATEATOM" > "$OUTPUTDIR/atom.xml" date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") sed "s/{{.Date}}/$date/" "$OUTPUTDIR/atom.xml" > "$OUTPUTDIR/atom.xml.tmp" mv "$OUTPUTDIR/atom.xml.tmp" "$OUTPUTDIR/atom.xml" # Remove tmp directory rm -r tmp fi