fr: add a second translation for keyword "privacy"; minor rewording of script explana...
[enc.git] / fr / kitchen / assemble-all-pages
1 #!/bin/bash
2
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.
7
8 # The page is NAME.html and the template is NAME.t.html. The template has
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
11 # markers to identify the borders of each deletion and indicate which
12 # page(s) the text between them belongs to.
13
14 # All the ingredients are is in [...]/enc/[lang]/kitchen/:
15
16 # Script: assemble-all-pages
17
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
22
23 # Includes: footer.html
24 # head.html
25 # javascript.html
26 # translist.html
27
28 # To regenerate the pages in [...]/enc/[lang]/:
29 # - in the terminal, cd to [...]/enc/[lang]/kitchen/ and enter:
30 # $ ./assemble-all-pages
31 # - alternatively, display the directory [...]/kitchen/ in the file browser
32 # (not the parent directory) and double-click on the script.
33
34 # And if anything goes wrong, you can do a git reset, right? ;-)
35
36 # ==========================================================================
37
38 set -e
39
40 # Create temporary files.
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
46
47 # List all the templates in the working directory.
48 if ls *.t.html > $names 2>/dev/null; then
49 sed -i 's,\.t\.html$,,' $names
50 else
51 echo "There is no template in this directory." && exit 1
52 fi
53
54 # Add the includes to the templates.
55 while read name; do
56 # echo $name
57 # Make sure there is a blank line before the first include, otherwise
58 # it will not be added properly.
59 cp $name.t.html ../$name.html && sed -i '1i\\n' ../$name.html
60
61 # List the includes.
62 grep '^<!-- include virtual="' ../$name.html |
63 sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list
64
65 # Add the includes.
66 while read include; do
67 sed "1,/^<!-- include virtual=\"$include\"/!d" ../$name.html > $before
68 sed "1,/^<!-- include virtual=\"$include\"/d" ../$name.html > $after
69 if [ -f "$include" ]; then
70 cat $before $include $after > ../$name.html
71 else
72 echo "$include is missing." && exit 1
73 fi
74 sed -i "/^<!-- include virtual=\"$include\"/d" ../$name.html
75 done < $list
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
98 # Delete any extra blank lines at the end of the page.
99 sed -i ':a /^\n*$/ {$d; N; ba}' ../$name.html
100 done < $names
101
102 exit 0