Commit | Line | Data |
---|---|---|
d2a7098b TG |
1 | #!/bin/bash |
2 | ||
d39837fa | 3 | # assemble-all-pages: generates a set of HTML pages with variable parts. |
d2a7098b | 4 | |
d39837fa TG |
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. | |
d2a7098b | 9 | |
d39837fa TG |
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/. | |
d2a7098b | 23 | |
435d2dec | 24 | # Script: assemble-all-pages |
d2a7098b | 25 | |
435d2dec TG |
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 | |
48c3acb0 | 30 | |
435d2dec | 31 | # Includes: footer.html |
d9a721e6 | 32 | # head.html (contains 2 alternate sets of keywords) |
435d2dec TG |
33 | # javascript.html |
34 | # translist.html | |
48c3acb0 | 35 | |
d39837fa TG |
36 | # To generate the pages in [...]/enc/[lang]/: |
37 | # - in the terminal, cd to [...]/enc/[lang]/kitchen/ and enter | |
48c3acb0 | 38 | # $ ./assemble-all-pages |
d39837fa | 39 | # - alternatively, display the kitchen/ directory in the file browser |
cae86991 | 40 | # (not the parent directory) and double-click on the script. |
48c3acb0 TG |
41 | |
42 | # And if anything goes wrong, you can do a git reset, right? ;-) | |
43 | ||
44 | # ========================================================================== | |
d2a7098b TG |
45 | |
46 | set -e | |
d2a7098b TG |
47 | |
48 | # Create temporary files. | |
f965450c TG |
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 | |
d2a7098b TG |
54 | |
55 | # List all the templates in the working directory. | |
f965450c TG |
56 | if ls *.t.html > $names 2>/dev/null; then |
57 | sed -i 's,\.t\.html$,,' $names | |
58 | else | |
d2a7098b TG |
59 | echo "There is no template in this directory." && exit 1 |
60 | fi | |
61 | ||
d9a721e6 TG |
62 | ## Add the includes to the templates. |
63 | ||
f965450c | 64 | while read name; do |
d2a7098b TG |
65 | # Make sure there is a blank line before the first include, otherwise |
66 | # it will not be added properly. | |
d9a721e6 | 67 | sed '1i\\n' $name.t.html > ../$name.html |
d2a7098b | 68 | # List the includes. |
f965450c | 69 | grep '^<!-- include virtual="' ../$name.html | |
48c3acb0 | 70 | sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list |
48c3acb0 | 71 | # Add the includes. |
d2a7098b | 72 | while read include; do |
f965450c TG |
73 | sed "1,/^<!-- include virtual=\"$include\"/!d" ../$name.html > $before |
74 | sed "1,/^<!-- include virtual=\"$include\"/d" ../$name.html > $after | |
d2a7098b | 75 | if [ -f "$include" ]; then |
f965450c | 76 | cat $before $include $after > ../$name.html |
d2a7098b TG |
77 | else |
78 | echo "$include is missing." && exit 1 | |
79 | fi | |
f965450c | 80 | sed -i "/^<!-- include virtual=\"$include\"/d" ../$name.html |
48c3acb0 | 81 | done < $list |
f965450c TG |
82 | done < $names |
83 | ||
d9a721e6 TG |
84 | ## Create mac.html and windows.html from index.html. |
85 | ||
f965450c TG |
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 | ||
d9a721e6 TG |
92 | ## Remove the irrelevant parts. |
93 | ||
f965450c TG |
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 | |
d9a721e6 | 100 | # Make the deletions. |
f965450c TG |
101 | while read deletion; do |
102 | sed -i "/^<!-- START DELETION $deletion/, \ | |
103 | /^<!-- END DELETION $deletion/d" ../$name.html | |
104 | done < $list | |
d9a721e6 | 105 | # Delete the markers and any extra blank lines at the end of the page. |
f965450c | 106 | sed -i '/^<!-- [A-Z]* DELETION/d' ../$name.html |
f965450c TG |
107 | sed -i ':a /^\n*$/ {$d; N; ba}' ../$name.html |
108 | done < $names | |
d2a7098b | 109 | |
d2a7098b | 110 | exit 0 |