Commit | Line | Data |
---|---|---|
d2a7098b TG |
1 | #!/bin/bash |
2 | ||
3 | # assemble-all-pages: includes the constant parts into all the HTML | |
4 | # templates in the working directory. | |
5 | ||
6 | # The name of a page is NAME.html and the name of the template is | |
7 | # NAME.t.html. The inclusion markers in the template are similar to | |
8 | # SSI directives, but for the "#". | |
9 | ||
10 | # The script is in the same directory as all the pieces. It can be | |
11 | # launched by double-clicking on it provided the path to the working | |
12 | # directory is set at the first line. | |
13 | ||
14 | # ===================================================================== | |
15 | ||
16 | wdir=~/GNU/enc/fr/kitchen | |
17 | ||
18 | set -e | |
19 | cd $wdir | |
20 | ||
21 | # Create temporary files. | |
22 | before=$(mktemp -t h2p.XXXXXX) || exit 1 | |
23 | after=$(mktemp -t h2p.XXXXXX) || exit 1 | |
24 | trap 'rm -f "$before" "$after"' EXIT | |
25 | ||
26 | # List all the templates in the working directory. | |
27 | if ! ls *.t.html > template-list ; then | |
28 | echo "There is no template in this directory." && exit 1 | |
29 | fi | |
30 | ||
31 | # Process each template of the list. | |
32 | while read template; do | |
33 | ||
34 | page=${template/.t/} | |
35 | echo $page | |
36 | ||
37 | # Make sure there is a blank line before the first include, otherwise | |
38 | # it will not be added properly. | |
39 | cp $template $page && sed -i '1i\\n' $page | |
40 | ||
41 | # List the includes. | |
42 | grep '<!-- include virtual="' $page | | |
43 | sed 's,^.*include virtual="\([^"]\+\).*$,\1,' > include-list | |
44 | ||
45 | # Add the listed includes and remove the marker. | |
46 | while read include; do | |
47 | sed "1,/<!-- include virtual=\"$include\"/!d" $page > $before | |
48 | sed "1,/<!-- include virtual=\"$include\"/d" $page > $after | |
49 | if [ -f "$include" ]; then | |
50 | cat $before $include $after > $page | |
51 | else | |
52 | echo "$include is missing." && exit 1 | |
53 | fi | |
54 | sed -i "/<!-- include virtual=\"$include\"/d" $page | |
55 | done < include-list | |
56 | ||
57 | # One item in Section 2a (Troubleshooting) of index.html has to be | |
58 | # removed from mac.html and windows.html. | |
59 | if [ "$page" == "mac.html" ] || [ "$page" == "windows.html" ]; then | |
60 | sed -i '/<!-- START DELETION -->/,/<!-- END DELETION -->/d' $page | |
61 | elif [ "$page" == "index.html" ]; then | |
62 | sed -i '/DELETION -->/d' $page | |
63 | fi | |
64 | ||
65 | # Delete extra blank lines at the end. | |
66 | sed -i ':a /^\n*$/ {$d; N; ba}' $page | |
67 | ||
68 | # Move the complete page to its final location. | |
69 | mv $page ../$page | |
70 | ||
71 | done < template-list | |
72 | exit 0 |