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
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 cp $name.t.html ..
/$name.html
&& sed -i '1i\\n' ..
/$name.html
62 grep '^<!-- include virtual="' ..
/$name.html |
63 sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list
66 while read include
; do
67 sed "1,/^<!-- include virtual=\"$include\"/!d" ..
/$name.html
> $before
68 sed "1,/^<!-- include virtual=\"$include\"/d" ..
/$name.html
> $after
69 if [ -f "$include" ]; then
70 cat $before $include $after > ..
/$name.html
72 echo "$include is missing." && exit 1
74 sed -i "/^<!-- include virtual=\"$include\"/d" ..
/$name.html
78 # Create mac.html and windows.html from index.html.
79 cp ..
/index.html ..
/mac.html
80 cp ..
/index.html ..
/windows.html
81 # add them to the list of page names.
83 echo 'windows' >> $names
85 # 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 sed -i '/^<!-- [A-Z]* DELETION/d' ..
/$name.html
98 # Delete any extra blank lines at the end of the page.
99 sed -i ':a /^\n*$/ {$d; N; ba}' ..
/$name.html