fr: margin-bottom doesn't work, try position.
[enc.git] / fr / kitchen / assemble-all-pages
1 #!/bin/bash
2
3 # assemble-all-pages: generates a set of HTML pages with variable parts.
4
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
8 # text.
9
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.
14
15 # The script processes all the templates in the working directory. The
16 # pages are created in the parent directory.
17
18 # Ideally, any modifications should be done to the templates or includes,
19 # not to the final pages.
20
21
22 # All the ingredients are in [...]/enc/[lang]/kitchen/.
23
24 # Script: assemble-all-pages
25
26 # Templates: confirmation.t.html
27 # index.t.html (contains variable parts for mac and windows)
28 # infographic.t.html
29 # next_steps.t.html
30
31 # Includes: footer.html
32 # head.html (contains 2 alternate sets of keywords)
33 # javascript.html
34 # translist.html
35
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.
41
42 # And if anything goes wrong, you can do a git reset, right? ;-)
43
44 # ==========================================================================
45
46 set -e
47
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
54
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
58 else
59 echo "There is no template in this directory." && exit 1
60 fi
61
62 ## Add the includes to the templates.
63
64 while read name; do
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
68 # List the includes.
69 grep '^<!-- include virtual="' ../$name.html |
70 sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list
71 # Add the includes.
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
77 else
78 echo "$include is missing." && exit 1
79 fi
80 sed -i "/^<!-- include virtual=\"$include\"/d" ../$name.html
81 done < $list
82 done < $names
83
84 ## Create mac.html and windows.html from index.html.
85
86 cp ../index.html ../mac.html
87 cp ../index.html ../windows.html
88 # add them to the list of page names.
89 echo 'mac' >> $names
90 echo 'windows' >> $names
91
92 ## Remove the irrelevant parts.
93
94 while read name ; do
95 # Find out which deletions apply.
96 grep '^<!-- START DELETION' ../$name.html \
97 | grep -v "$name" \
98 | sed 's%^<!-- START DELETION \([0-9][0-9]\),.*$%\1%' > $list
99 echo $name
100 # Make the deletions.
101 while read deletion; do
102 sed -i "/^<!-- START DELETION $deletion/, \
103 /^<!-- END DELETION $deletion/d" ../$name.html
104 done < $list
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
108 done < $names
109
110 exit 0