## Synopsis: assemble-all-pages
-## Overview
+## Description
# Each page is built from a template and one or several includes, as usual;
# in addition, several versions of a page can be built from a single
# ===========================================================================
set -e
+set -o pipefail
-close_term () {
+function close_term () {
printf '\n%s' '*** Close the terminal window or press Return.'; read OK
test -z "$OK" && exit $1
}
# Create temporary files.
-names=$(mktemp -t aap.XXXXXX) || close_or_exit 1
-list=$(mktemp -t aap.XXXXXX) || close_or_exit 1
-before=$(mktemp -t aap.XXXXXX) || close_or_exit 1
-after=$(mktemp -t aap.XXXXXX) || close_or_exit 1
+names=$(mktemp -t aap.XXXXXX) || close_term 1
+list=$(mktemp -t aap.XXXXXX) || close_term 1
+before=$(mktemp -t aap.XXXXXX) || close_term 1
+after=$(mktemp -t aap.XXXXXX) || close_term 1
trap 'rm -f "$names" "$list" "$before" "$after"' EXIT
# List all the templates in the working directory.
if [ -f "$include" ]; then
cat $before $include $after > ../$name.html
else
- echo "$include is missing." && exit 1
+ echo "$include is missing." && close_term 1
fi
sed -i "/^<!-- include virtual=\"$include\"/d" ../$name.html
done < $list
| grep -v "$name" \
| sed 's%^<!-- START DELETION \([0-9][0-9]\),.*$%\1%' > $list
echo $name
- # Make the deletions.
+ # Delete.
while read deletion; do
sed -i "/^<!-- START DELETION $deletion/, \
/^<!-- END DELETION $deletion/d" ../$name.html
done < $list
- # Delete the markers and any extra blank lines at the end of the page.
+ # Remove the markers and any extra blank lines at the end of the page.
sed -i '/^<!-- [A-Z]* DELETION/d' ../$name.html
sed -i ':a /^\n*$/ {$d; N; ba}' ../$name.html
done < $names