archived old versions of the web pages
[enc.git] / old / ru / kitchen / assemble-all-pages
CommitLineData
66dc5366
I
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
8d0e67b7 30# workshops.t.html
66dc5366
I
31
32# Includes: footer.html
de21d188 33# head.html
66dc5366
I
34# javascript.html
35# translist.html
36
37## Graphic-user-interface howto
38
39# - Place the script in the same directory as the templates.
40# - Display this directory in the file browser (do not just unfold the parent
41# directory) and double-click on the script.
42
43# And if anything goes wrong, you can do a git reset, right? ;-)
44
45# ===========================================================================
46
47set -e
48set -o pipefail
49
66dc5366
I
50# Create temporary files.
51names=$(mktemp -t aap.XXXXXX) || close_term 1
52list=$(mktemp -t aap.XXXXXX) || close_term 1
53before=$(mktemp -t aap.XXXXXX) || close_term 1
54after=$(mktemp -t aap.XXXXXX) || close_term 1
55trap 'rm -f "$names" "$list" "$before" "$after"' EXIT
56
57# List all the templates in the working directory.
58if ls *.t.html > $names 2>/dev/null; then
59 sed -i 's,\.t\.html$,,' $names
60else
61 echo "*** There is no template in this directory." && close_term 1
62fi
63
64## Add the includes to the templates.
65
66while read name; do
67 # Make sure there is a blank line before the first include, otherwise
68 # it will not be added properly.
69 sed '1i\\n' $name.t.html > ../$name.html
70 # List the includes.
71 grep '^<!-- include virtual="' ../$name.html |
72 sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list
73 # Add the includes.
74 while read include; do
75 sed "1,/^<!-- include virtual=\"$include\"/!d" ../$name.html > $before
76 sed "1,/^<!-- include virtual=\"$include\"/d" ../$name.html > $after
77 if [ -f "$include" ]; then
78 cat $before $include $after > ../$name.html
79 else
80 echo "$include is missing." && close_term 1
81 fi
82 sed -i "/^<!-- include virtual=\"$include\"/d" ../$name.html
83 done < $list
84done < $names
85
86## Create mac.html and windows.html from index.html.
87
88cp ../index.html ../mac.html
89cp ../index.html ../windows.html
90# add them to the list of page names.
91echo 'mac' >> $names
92echo 'windows' >> $names
93
94## Remove the irrelevant parts.
95
96while read name ; do
97 # Find out which deletions apply.
eac5d91d
TG
98 grep '^<!-- START DELETION' ../$name.html |
99 grep -v "$name" > $list || true
100 sed -i 's%^<!-- START DELETION \([0-9][0-9]\),.*$%\1%' $list
66dc5366
I
101 # Delete.
102 while read deletion; do
103 sed -i "/^<!-- START DELETION $deletion/, \
104 /^<!-- END DELETION $deletion/d" ../$name.html
105 done < $list
106 # Remove the markers and any extra blank lines at the end of the page.
107 sed -i '/^<!-- [A-Z]* DELETION/d' ../$name.html
108 sed -i ':a /^\n*$/ {$d; N; ba}' ../$name.html
109done < $names