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
29 # To regenerate the pages in [...]/enc/[lang]/:
30 # - In the terminal, cd to [...]/enc/[lang]/kitchen/ and enter:
31 # $ ./assemble-all-pages
32 # - Or, in the file browser, display the directory [...]/kitchen/ (not its
33 # parent) and double-click on the script.
35 # And if anything goes wrong, you can do a git reset, right? ;-)
37 # ==========================================================================
41 # Create temporary files.
42 before
=$
(mktemp
-t h2p.XXXXXX
) ||
exit 1
43 after
=$
(mktemp
-t h2p.XXXXXX
) ||
exit 1
44 templates
=$
(mktemp
-t h2p.XXXXXX
) ||
exit 1
45 list
=$
(mktemp
-t h2p.XXXXXX
) ||
exit 1 # includes, then deletion markers
46 deletions
=$
(mktemp
-t h2p.XXXXXX
) ||
exit 1
47 trap 'rm -f "$before" "$after" "$templates" "$list" "$deletions"' EXIT
49 # List all the templates in the working directory.
50 if ! ls *.t.html
> $templates 2>/dev
/null
; then
51 echo "There is no template in this directory." && exit 1
54 # Process each template in the list.
55 while read template
; do
60 # Make sure there is a blank line before the first include, otherwise
61 # it will not be added properly.
62 cp $template ..
/$page && sed -i '1i\\n' ..
/$page
65 grep '^<!-- include virtual="' ..
/$page |
66 sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list
69 while read include
; do
70 sed "1,/^<!-- include virtual=\"$include\"/!d" ..
/$page > $before
71 sed "1,/^<!-- include virtual=\"$include\"/d" ..
/$page > $after
72 if [ -f "$include" ]; then
73 cat $before $include $after > ..
/$page
75 echo "$include is missing." && exit 1
77 sed -i "/^<!-- include virtual=\"$include\"/d" ..
/$page
80 # Create mac.html and windows.html from index.html and delete the
82 if [ $page == "index.html" ]; then
83 cp ..
/$page ..
/mac.html
84 cp ..
/$page ..
/windows.html
85 # List the deletion markers.
86 grep '^<!-- START DELETION' ..
/index.html
> $list
87 # Process each page separately.
88 for variant
in index mac windows
; do
89 # Find out which deletions should be made.
90 grep -v "$variant" $list \
91 |
sed 's%^<!-- START DELETION \([0-9][0-9]\?\),.*$%\1%' > $deletions
93 while read deletion
; do
94 sed -i "/^<!-- START DELETION $deletion/,\
95 /^<!-- END DELETION $deletion/d" ..
/$variant.html
97 sed -i '/^<!-- [A-Z]* DELETION/d' ..
/$variant.html
100 # Delete any extra blank lines at the end of the page.
101 sed -i ':a /^\n*$/ {$d; N; ba}' ..
/*.html