# SSWG - Simple Static Website Generator #!/bin/sh SSWG_OUTPUT_DIR="_static" SSWG_ASSETS_DIR="_assets" SSWG_PAGES_DIR="_pages" SSWG_HEADER_TEMPLATE="_header.t.html" SSWG_FOOTER_TEMPLATE="_footer.t.html" rm -rf "$SSWG_OUTPUT_DIR" mkdir "$SSWG_OUTPUT_DIR" # Copy static assets cp -r "$SSWG_ASSETS_DIR"/* "$SSWG_OUTPUT_DIR"/. # Generate HTML pages for page in $(find "$SSWG_PAGES_DIR" -iname '*.html' -o \ -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png'); do filename="$SSWG_OUTPUT_DIR/${page##$SSWG_PAGES_DIR/}" mkdir -p "`dirname $filename`" if [ "${filename##*.}" = "html" ]; then # prepose header cat "$SSWG_HEADER_TEMPLATE" >> "$filename" # Fix indentation in the generated source cat "$page" | awk ' BEGIN {print ""} FNR>3 {print " " $0} END {print ""}' >> "$filename" # append footer cat "$SSWG_FOOTER_TEMPLATE" >> "$filename" # macro substitution eval `cat "$page" | awk 'FNR<3'` sed -i'' "s@TITLE@$TITLE@g" "$filename" sed -i'' "s@DESCRIPTION@$DESCRIPTION@g" "$filename" # remove comments sed -i'' "/^[ \t]*#/d" "$filename" # remove indentation before whitespaces+pipe # useful e.g. with
 tags
        sed -i'' "s/^[ \t]*|//g" "$filename"  # remove
    else
        cp $page $filename
    fi;
done;