fr: reword explanations.
[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 # head1.html
25 # head2.html
26 # javascript.html
27 # translist.html
28
29 # To regenerate the pages in [...]/enc/[lang]/:
30 # - In the terminal, cd to [...]/enc/[lang]/kitchen/ and enter:
31 # $ ./assemble-all-pages
32 # - Or, in the file browser, display the directory [...]/kitchen/ (not its
33 # parent) and double-click on the script.
34
35 # And if anything goes wrong, you can do a git reset, right? ;-)
36
37 # ==========================================================================
38
39 set -e
40
41 # Create temporary files.
42 before=$(mktemp -t h2p.XXXXXX) || exit 1
43 after=$(mktemp -t h2p.XXXXXX) || exit 1
44 templates=$(mktemp -t h2p.XXXXXX) || exit 1
45 list=$(mktemp -t h2p.XXXXXX) || exit 1 # includes, then deletion markers
46 deletions=$(mktemp -t h2p.XXXXXX) || exit 1
47 trap 'rm -f "$before" "$after" "$templates" "$list" "$deletions"' EXIT
48
49 # List all the templates in the working directory.
50 if ! ls *.t.html > $templates 2>/dev/null; then
51 echo "There is no template in this directory." && exit 1
52 fi
53
54 # Process each template in the list.
55 while read template; do
56
57 page=${template/.t/}
58 echo $page
59
60 # Make sure there is a blank line before the first include, otherwise
61 # it will not be added properly.
62 cp $template ../$page && sed -i '1i\\n' ../$page
63
64 # List the includes.
65 grep '^<!-- include virtual="' ../$page |
66 sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list
67
68 # Add the includes.
69 while read include; do
70 sed "1,/^<!-- include virtual=\"$include\"/!d" ../$page > $before
71 sed "1,/^<!-- include virtual=\"$include\"/d" ../$page > $after
72 if [ -f "$include" ]; then
73 cat $before $include $after > ../$page
74 else
75 echo "$include is missing." && exit 1
76 fi
77 sed -i "/^<!-- include virtual=\"$include\"/d" ../$page
78 done < $list
79
80 # Create mac.html and windows.html from index.html and delete the
81 # irrelevant parts.
82 if [ $page == "index.html" ]; then
83 cp ../$page ../mac.html
84 cp ../$page ../windows.html
85 # List the deletion markers.
86 grep '^<!-- START DELETION' ../index.html > $list
87 # Process each page separately.
88 for variant in index mac windows; do
89 # Find out which deletions should be made.
90 grep -v "$variant" $list \
91 | sed 's%^<!-- START DELETION \([0-9][0-9]\?\),.*$%\1%' > $deletions
92 # Delete.
93 while read deletion; do
94 sed -i "/^<!-- START DELETION $deletion/,\
95 /^<!-- END DELETION $deletion/d" ../$variant.html
96 done < $deletions
97 sed -i '/^<!-- [A-Z]* DELETION/d' ../$variant.html
98 done
99 fi
100 # Delete any extra blank lines at the end of the page.
101 sed -i ':a /^\n*$/ {$d; N; ba}' ../*.html
102
103 done < $templates
104 exit 0