Commit | Line | Data |
---|---|---|
d2a7098b TG |
1 | #!/bin/bash |
2 | ||
435d2dec TG |
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 | |
6 | # parts. | |
d2a7098b | 7 | |
48c3acb0 | 8 | # The page is NAME.html and the template is NAME.t.html. The template has |
435d2dec TG |
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 | |
48c3acb0 | 11 | # markers to identify the borders of each deletion and indicate which |
435d2dec | 12 | # page(s) the text between them belongs to. |
d2a7098b | 13 | |
435d2dec | 14 | # All the ingredients are is in [...]/enc/[lang]/kitchen/: |
d2a7098b | 15 | |
435d2dec | 16 | # Script: assemble-all-pages |
d2a7098b | 17 | |
435d2dec TG |
18 | # Templates: confirmation.t.html |
19 | # index.t.html (contains variable parts for mac and windows) | |
20 | # infographic.t.html | |
21 | # next_steps.t.html | |
48c3acb0 | 22 | |
435d2dec | 23 | # Includes: footer.html |
f965450c | 24 | # head.html |
435d2dec TG |
25 | # javascript.html |
26 | # translist.html | |
48c3acb0 | 27 | |
435d2dec | 28 | # To regenerate the pages in [...]/enc/[lang]/: |
cae86991 | 29 | # - in the terminal, cd to [...]/enc/[lang]/kitchen/ and enter: |
48c3acb0 | 30 | # $ ./assemble-all-pages |
cae86991 TG |
31 | # - alternatively, display the directory [...]/kitchen/ in the file browser |
32 | # (not the parent directory) and double-click on the script. | |
48c3acb0 TG |
33 | |
34 | # And if anything goes wrong, you can do a git reset, right? ;-) | |
35 | ||
36 | # ========================================================================== | |
d2a7098b TG |
37 | |
38 | set -e | |
d2a7098b TG |
39 | |
40 | # Create temporary files. | |
f965450c TG |
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 | |
d2a7098b TG |
46 | |
47 | # List all the templates in the working directory. | |
f965450c TG |
48 | if ls *.t.html > $names 2>/dev/null; then |
49 | sed -i 's,\.t\.html$,,' $names | |
50 | else | |
d2a7098b TG |
51 | echo "There is no template in this directory." && exit 1 |
52 | fi | |
53 | ||
f965450c TG |
54 | # Add the includes to the templates. |
55 | while read name; do | |
56 | # echo $name | |
d2a7098b TG |
57 | # Make sure there is a blank line before the first include, otherwise |
58 | # it will not be added properly. | |
f965450c | 59 | cp $name.t.html ../$name.html && sed -i '1i\\n' ../$name.html |
d2a7098b TG |
60 | |
61 | # List the includes. | |
f965450c | 62 | grep '^<!-- include virtual="' ../$name.html | |
48c3acb0 | 63 | sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list |
d2a7098b | 64 | |
48c3acb0 | 65 | # Add the includes. |
d2a7098b | 66 | while read include; do |
f965450c TG |
67 | sed "1,/^<!-- include virtual=\"$include\"/!d" ../$name.html > $before |
68 | sed "1,/^<!-- include virtual=\"$include\"/d" ../$name.html > $after | |
d2a7098b | 69 | if [ -f "$include" ]; then |
f965450c | 70 | cat $before $include $after > ../$name.html |
d2a7098b TG |
71 | else |
72 | echo "$include is missing." && exit 1 | |
73 | fi | |
f965450c | 74 | sed -i "/^<!-- include virtual=\"$include\"/d" ../$name.html |
48c3acb0 | 75 | done < $list |
f965450c TG |
76 | done < $names |
77 | ||
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. | |
82 | echo 'mac' >> $names | |
83 | echo 'windows' >> $names | |
84 | ||
85 | # Remove the irrelevant parts. | |
86 | while read name ; do | |
87 | # Find out which deletions apply. | |
88 | grep '^<!-- START DELETION' ../$name.html \ | |
89 | | grep -v "$name" \ | |
90 | | sed 's%^<!-- START DELETION \([0-9][0-9]\),.*$%\1%' > $list | |
91 | echo $name | |
92 | # Delete. | |
93 | while read deletion; do | |
94 | sed -i "/^<!-- START DELETION $deletion/, \ | |
95 | /^<!-- END DELETION $deletion/d" ../$name.html | |
96 | done < $list | |
97 | sed -i '/^<!-- [A-Z]* DELETION/d' ../$name.html | |
48c3acb0 | 98 | # Delete any extra blank lines at the end of the page. |
f965450c TG |
99 | sed -i ':a /^\n*$/ {$d; N; ba}' ../$name.html |
100 | done < $names | |
d2a7098b | 101 | |
d2a7098b | 102 | exit 0 |