Commit | Line | Data |
---|---|---|
d2a7098b TG |
1 | #!/bin/bash |
2 | ||
4f8bf1ae TG |
3 | ## assemble-all-pages -- generate a set of HTML pages with variable parts |
4 | # for emailselfdefense.fsf.org | |
5 | ||
6 | ## Synopsis: assemble-all-pages | |
7 | ||
8 | ## Overview | |
d2a7098b | 9 | |
d39837fa TG |
10 | # Each page is built from a template and one or several includes, as usual; |
11 | # in addition, several versions of a page can be built from a single | |
12 | # template which contains all the variable parts, by deleting irrelevant | |
13 | # text. | |
d2a7098b | 14 | |
d39837fa TG |
15 | # The templates have inclusion markers (similar to SSI directives, except |
16 | # for the lack of "#") to indicate where the constant parts are to be | |
17 | # inserted, and deletion markers to identify the borders of each deletion | |
18 | # and indicate which page(s) the text between those borders belongs to. | |
19 | ||
4f8bf1ae | 20 | # The script processes all the templates in the working directory and the |
d39837fa TG |
21 | # pages are created in the parent directory. |
22 | ||
23 | # Ideally, any modifications should be done to the templates or includes, | |
24 | # not to the final pages. | |
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 | |
4f8bf1ae TG |
36 | ## Graphic-user-interface howto |
37 | ||
38 | # - Place the script in the same directory as the templates. | |
39 | # - Display this directory in the file browser (do not just unfold the parent | |
40 | # directory) and double-click on the script. | |
48c3acb0 TG |
41 | |
42 | # And if anything goes wrong, you can do a git reset, right? ;-) | |
43 | ||
4f8bf1ae | 44 | # =========================================================================== |
d2a7098b TG |
45 | |
46 | set -e | |
d2a7098b | 47 | |
4f8bf1ae TG |
48 | close_term () { |
49 | printf '\n%s' '*** Close the terminal window or press Return.'; read OK | |
50 | test -z "$OK" && exit $1 | |
51 | } | |
52 | ||
d2a7098b | 53 | # Create temporary files. |
4f8bf1ae TG |
54 | names=$(mktemp -t aap.XXXXXX) || close_or_exit 1 |
55 | list=$(mktemp -t aap.XXXXXX) || close_or_exit 1 | |
56 | before=$(mktemp -t aap.XXXXXX) || close_or_exit 1 | |
57 | after=$(mktemp -t aap.XXXXXX) || close_or_exit 1 | |
f965450c | 58 | trap 'rm -f "$names" "$list" "$before" "$after"' EXIT |
d2a7098b TG |
59 | |
60 | # List all the templates in the working directory. | |
f965450c TG |
61 | if ls *.t.html > $names 2>/dev/null; then |
62 | sed -i 's,\.t\.html$,,' $names | |
63 | else | |
4f8bf1ae | 64 | echo "*** There is no template in this directory." && close_term 1 |
d2a7098b TG |
65 | fi |
66 | ||
d9a721e6 TG |
67 | ## Add the includes to the templates. |
68 | ||
f965450c | 69 | while read name; do |
d2a7098b TG |
70 | # Make sure there is a blank line before the first include, otherwise |
71 | # it will not be added properly. | |
d9a721e6 | 72 | sed '1i\\n' $name.t.html > ../$name.html |
d2a7098b | 73 | # List the includes. |
f965450c | 74 | grep '^<!-- include virtual="' ../$name.html | |
48c3acb0 | 75 | sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list |
48c3acb0 | 76 | # Add the includes. |
d2a7098b | 77 | while read include; do |
f965450c TG |
78 | sed "1,/^<!-- include virtual=\"$include\"/!d" ../$name.html > $before |
79 | sed "1,/^<!-- include virtual=\"$include\"/d" ../$name.html > $after | |
d2a7098b | 80 | if [ -f "$include" ]; then |
f965450c | 81 | cat $before $include $after > ../$name.html |
d2a7098b TG |
82 | else |
83 | echo "$include is missing." && exit 1 | |
84 | fi | |
f965450c | 85 | sed -i "/^<!-- include virtual=\"$include\"/d" ../$name.html |
48c3acb0 | 86 | done < $list |
f965450c TG |
87 | done < $names |
88 | ||
d9a721e6 TG |
89 | ## Create mac.html and windows.html from index.html. |
90 | ||
f965450c TG |
91 | cp ../index.html ../mac.html |
92 | cp ../index.html ../windows.html | |
93 | # add them to the list of page names. | |
94 | echo 'mac' >> $names | |
95 | echo 'windows' >> $names | |
96 | ||
d9a721e6 TG |
97 | ## Remove the irrelevant parts. |
98 | ||
f965450c TG |
99 | while read name ; do |
100 | # Find out which deletions apply. | |
101 | grep '^<!-- START DELETION' ../$name.html \ | |
102 | | grep -v "$name" \ | |
103 | | sed 's%^<!-- START DELETION \([0-9][0-9]\),.*$%\1%' > $list | |
104 | echo $name | |
d9a721e6 | 105 | # Make the deletions. |
f965450c TG |
106 | while read deletion; do |
107 | sed -i "/^<!-- START DELETION $deletion/, \ | |
108 | /^<!-- END DELETION $deletion/d" ../$name.html | |
109 | done < $list | |
d9a721e6 | 110 | # Delete the markers and any extra blank lines at the end of the page. |
f965450c | 111 | sed -i '/^<!-- [A-Z]* DELETION/d' ../$name.html |
f965450c TG |
112 | sed -i ':a /^\n*$/ {$d; N; ba}' ../$name.html |
113 | done < $names | |
d2a7098b | 114 | |
4f8bf1ae | 115 | close_term 0 |