Trying to fix the broken posturl in the next steps supporter signup.
[enc-live.git] / ru / kitchen / assemble-all-pages
1 #!/bin/bash
2
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 ## Description
9
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.
14
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
20 # The script processes all the templates in the working directory and the
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
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 ## 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.
41
42 # And if anything goes wrong, you can do a git reset, right? ;-)
43
44 # ===========================================================================
45
46 set -e
47 set -o pipefail
48
49 function close_term () {
50 echo;
51 echo '*** Close the terminal window or press Return.';
52 exit $1
53 }
54
55 # Create temporary files.
56 names=$(mktemp -t aap.XXXXXX) || close_term 1
57 list=$(mktemp -t aap.XXXXXX) || close_term 1
58 before=$(mktemp -t aap.XXXXXX) || close_term 1
59 after=$(mktemp -t aap.XXXXXX) || close_term 1
60 trap 'rm -f "$names" "$list" "$before" "$after"' EXIT
61
62 # List all the templates in the working directory.
63 if ls *.t.html > $names 2>/dev/null; then
64 sed -i 's,\.t\.html$,,' $names
65 else
66 echo "*** There is no template in this directory." && close_term 1
67 fi
68
69 ## Add the includes to the templates.
70
71 while read name; do
72 # Make sure there is a blank line before the first include, otherwise
73 # it will not be added properly.
74 sed '1i\\n' $name.t.html > ../$name.html
75 # List the includes.
76 grep '^<!-- include virtual="' ../$name.html |
77 sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list
78 # Add the includes.
79 while read include; do
80 sed "1,/^<!-- include virtual=\"$include\"/!d" ../$name.html > $before
81 sed "1,/^<!-- include virtual=\"$include\"/d" ../$name.html > $after
82 if [ -f "$include" ]; then
83 cat $before $include $after > ../$name.html
84 else
85 echo "$include is missing." && close_term 1
86 fi
87 sed -i "/^<!-- include virtual=\"$include\"/d" ../$name.html
88 done < $list
89 done < $names
90
91 ## Create mac.html and windows.html from index.html.
92
93 cp ../index.html ../mac.html
94 cp ../index.html ../windows.html
95 # add them to the list of page names.
96 echo 'mac' >> $names
97 echo 'windows' >> $names
98
99 ## Remove the irrelevant parts.
100
101 while read name ; do
102 # Find out which deletions apply.
103 grep '^<!-- START DELETION' ../$name.html \
104 | grep -v "$name" \
105 | sed 's%^<!-- START DELETION \([0-9][0-9]\),.*$%\1%' > $list
106 echo $name
107 # Delete.
108 while read deletion; do
109 sed -i "/^<!-- START DELETION $deletion/, \
110 /^<!-- END DELETION $deletion/d" ../$name.html
111 done < $list
112 # Remove the markers and any extra blank lines at the end of the page.
113 sed -i '/^<!-- [A-Z]* DELETION/d' ../$name.html
114 sed -i ':a /^\n*$/ {$d; N; ba}' ../$name.html
115 done < $names
116
117 close_term 0