3 # "assemble-all-pages" inserts the constant parts into all HTML templates
4 # in the working directory and creates the OS-specific pages by removing
5 # the irrelevant text from a common file which contains the OS-variable
8 # The page is NAME.html and the template is NAME.t.html. The template has
9 # inclusion markers (similar to SSI directives, except for the lack of "#")
10 # to indicate where the constant parts are to be inserted, and deletion
11 # markers to identify the borders of each deletion and indicate which
12 # page(s) the text between them belongs to.
14 # All the ingredients are is in [...]/enc/[lang]/kitchen/:
16 # Script: assemble-all-pages
18 # Templates: confirmation.t.html
19 # index.t.html (contains variable parts for mac and windows)
23 # Includes: footer.html
24 # head.html (contains 2 alternate sets of keywords)
28 # To regenerate the pages in [...]/enc/[lang]/:
29 # - in the terminal, cd to [...]/enc/[lang]/kitchen/ and enter:
30 # $ ./assemble-all-pages
31 # - alternatively, display the directory [...]/kitchen/ in the file browser
32 # (not the parent directory) and double-click on the script.
34 # And if anything goes wrong, you can do a git reset, right? ;-)
36 # ==========================================================================
40 # Create temporary files.
41 names
=$
(mktemp
-t aap.XXXXXX
) ||
exit 1
42 list
=$
(mktemp
-t aap.XXXXXX
) ||
exit 1
43 before
=$
(mktemp
-t aap.XXXXXX
) ||
exit 1
44 after
=$
(mktemp
-t aap.XXXXXX
) ||
exit 1
45 trap 'rm -f "$names" "$list" "$before" "$after"' EXIT
47 # List all the templates in the working directory.
48 if ls *.t.html
> $names 2>/dev
/null
; then
49 sed -i 's,\.t\.html$,,' $names
51 echo "There is no template in this directory." && exit 1
54 ## Add the includes to the templates.
57 # Make sure there is a blank line before the first include, otherwise
58 # it will not be added properly.
59 sed '1i\\n' $name.t.html
> ..
/$name.html
61 grep '^<!-- include virtual="' ..
/$name.html |
62 sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list
64 while read include
; do
65 sed "1,/^<!-- include virtual=\"$include\"/!d" ..
/$name.html
> $before
66 sed "1,/^<!-- include virtual=\"$include\"/d" ..
/$name.html
> $after
67 if [ -f "$include" ]; then
68 cat $before $include $after > ..
/$name.html
70 echo "$include is missing." && exit 1
72 sed -i "/^<!-- include virtual=\"$include\"/d" ..
/$name.html
76 ## Create mac.html and windows.html from index.html.
78 cp ..
/index.html ..
/mac.html
79 cp ..
/index.html ..
/windows.html
80 # add them to the list of page names.
82 echo 'windows' >> $names
84 ## Remove the irrelevant parts.
87 # Find out which deletions apply.
88 grep '^<!-- START DELETION' ..
/$name.html \
90 |
sed 's%^<!-- START DELETION \([0-9][0-9]\),.*$%\1%' > $list
93 while read deletion
; do
94 sed -i "/^<!-- START DELETION $deletion/, \
95 /^<!-- END DELETION $deletion/d" ..
/$name.html
97 # Delete the markers and any extra blank lines at the end of the page.
98 sed -i '/^<!-- [A-Z]* DELETION/d' ..
/$name.html
99 sed -i ':a /^\n*$/ {$d; N; ba}' ..
/$name.html