#!/bin/bash # assemble-all-pages: includes the constant parts into all the HTML # templates in the working directory. # The name of a page is NAME.html and the name of the template is # NAME.t.html. The inclusion markers in the template are similar to # SSI directives, but for the "#". # The script is in the same directory as all the pieces. It can be # launched by double-clicking on it provided the path to the working # directory is set at the first line. # ===================================================================== wdir=~/GNU/enc/fr/kitchen set -e cd $wdir # Create temporary files. before=$(mktemp -t h2p.XXXXXX) || exit 1 after=$(mktemp -t h2p.XXXXXX) || exit 1 trap 'rm -f "$before" "$after"' EXIT # List all the templates in the working directory. if ! ls *.t.html > template-list ; then echo "There is no template in this directory." && exit 1 fi # Process each template of the list. while read template; do page=${template/.t/} echo $page # Make sure there is a blank line before the first include, otherwise # it will not be added properly. cp $template $page && sed -i '1i\\n' $page # List the includes. grep '/,//d' $page elif [ "$page" == "index.html" ]; then sed -i '/DELETION -->/d' $page fi # Delete extra blank lines at the end. sed -i ':a /^\n*$/ {$d; N; ba}' $page # Move the complete page to its final location. mv $page ../$page done < template-list exit 0