fr: templates for all 6 pages and new script "assemble-all-pages"; fix a few errors...
[enc.git] / fr / kitchen / assemble-page
1 #!/bin/sh
2
3 # assemble-page: includes the constant parts into an HTML template.
4
5 # The name of the page is NAME.html and the name of the template is
6 # NAME.t.html. The inclusion markers in the template are similar to
7 # SSI directives, but for the "#".
8
9 # The script and all the pieces are in the same directory.
10 # cd to that directory and run:
11
12 # $ ./assemble-page NAME
13
14 # ===================================================================
15
16 # Create temporary files.
17 before=$(mktemp -t h2p.XXXXXX) || exit 1
18 after=$(mktemp -t h2p.XXXXXX) || exit 1
19 trap 'rm -f "$before" "$after"' EXIT
20
21 # Make sure there is a blank line before the first include, otherwise
22 # it will not be added properly.
23 cp $1.t.html $1.html && sed -i '1i\\n' $1.html
24
25 # List the includes.
26 grep '<!-- include virtual="' $1.html |
27 sed 's,^.*include virtual="\([^"]\+\).*$,\1,' > include-list
28
29 # Add the listed includes and remove the marker.
30 while read i; do
31 sed "1,/<!-- include virtual=\"$i\"/!d" $1.html > $before
32 sed "1,/<!-- include virtual=\"$i\"/d" $1.html > $after
33 if [ -f "$i" ]; then
34 cat $before $i $after > $1.html
35 else
36 echo "$i is missing."
37 fi
38 sed -i "/<!-- include virtual=\"$i\"/d" $1.html
39 done < include-list
40
41 # One item in Section 2a (Troubleshooting) of index.html has to be
42 # removed from mac.html and windows.html.
43 if [ "$1" == "mac" ] || [ "$1" == "windows" ]; then
44 sed -i '/<!-- START DELETION -->/,/<!-- END DELETION -->/d' $1
45 elif [ "$1" == "index" ]; then
46 sed -i '/DELETION -->/d' $1
47 fi
48
49 # Delete extra blank lines at the end.
50 sed -i ':a /^\n*$/ {$d; N; ba}' ../$1.html