3 # assemble-all-pages: generates a set of HTML pages with variable parts.
5 # Each page is built from a template and one or several includes, as usual;
6 # in addition, several versions of a page can be built from a single
7 # template which contains all the variable parts, by deleting irrelevant
10 # The templates have inclusion markers (similar to SSI directives, except
11 # for the lack of "#") to indicate where the constant parts are to be
12 # inserted, and deletion markers to identify the borders of each deletion
13 # and indicate which page(s) the text between those borders belongs to.
15 # The script processes all the templates in the working directory. The
16 # pages are created in the parent directory.
18 # Ideally, any modifications should be done to the templates or includes,
19 # not to the final pages.
22 # All the ingredients are in [...]/enc/[lang]/kitchen/.
24 # Script: assemble-all-pages
26 # Templates: confirmation.t.html
27 # index.t.html (contains variable parts for mac and windows)
31 # Includes: footer.html
32 # head.html (contains 2 alternate sets of keywords)
36 # To generate the pages in [...]/enc/[lang]/:
37 # - in the terminal, cd to [...]/enc/[lang]/kitchen/ and enter
38 # $ ./assemble-all-pages
39 # - alternatively, display the kitchen/ directory in the file browser
40 # (not the parent directory) and double-click on the script.
42 # And if anything goes wrong, you can do a git reset, right? ;-)
44 # ==========================================================================
48 # Create temporary files.
49 names
=$
(mktemp
-t aap.XXXXXX
) ||
exit 1
50 list
=$
(mktemp
-t aap.XXXXXX
) ||
exit 1
51 before
=$
(mktemp
-t aap.XXXXXX
) ||
exit 1
52 after
=$
(mktemp
-t aap.XXXXXX
) ||
exit 1
53 trap 'rm -f "$names" "$list" "$before" "$after"' EXIT
55 # List all the templates in the working directory.
56 if ls *.t.html
> $names 2>/dev
/null
; then
57 sed -i 's,\.t\.html$,,' $names
59 echo "There is no template in this directory." && exit 1
62 ## Add the includes to the templates.
65 # Make sure there is a blank line before the first include, otherwise
66 # it will not be added properly.
67 sed '1i\\n' $name.t.html
> ..
/$name.html
69 grep '^<!-- include virtual="' ..
/$name.html |
70 sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list
72 while read include
; do
73 sed "1,/^<!-- include virtual=\"$include\"/!d" ..
/$name.html
> $before
74 sed "1,/^<!-- include virtual=\"$include\"/d" ..
/$name.html
> $after
75 if [ -f "$include" ]; then
76 cat $before $include $after > ..
/$name.html
78 echo "$include is missing." && exit 1
80 sed -i "/^<!-- include virtual=\"$include\"/d" ..
/$name.html
84 ## Create mac.html and windows.html from index.html.
86 cp ..
/index.html ..
/mac.html
87 cp ..
/index.html ..
/windows.html
88 # add them to the list of page names.
90 echo 'windows' >> $names
92 ## Remove the irrelevant parts.
95 # Find out which deletions apply.
96 grep '^<!-- START DELETION' ..
/$name.html \
98 |
sed 's%^<!-- START DELETION \([0-9][0-9]\),.*$%\1%' > $list
100 # Make the deletions.
101 while read deletion
; do
102 sed -i "/^<!-- START DELETION $deletion/, \
103 /^<!-- END DELETION $deletion/d" ..
/$name.html
105 # Delete the markers and any extra blank lines at the end of the page.
106 sed -i '/^<!-- [A-Z]* DELETION/d' ..
/$name.html
107 sed -i ':a /^\n*$/ {$d; N; ba}' ..
/$name.html