modified: it/confirmation.html
[enc-live.git] / fr / kitchen / assemble-all-pages
CommitLineData
d2a7098b
TG
1#!/bin/bash
2
435d2dec
TG
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.
d2a7098b 7
48c3acb0 8# The page is NAME.html and the template is NAME.t.html. The template has
435d2dec
TG
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
48c3acb0 11# markers to identify the borders of each deletion and indicate which
435d2dec 12# page(s) the text between them belongs to.
d2a7098b 13
435d2dec 14# All the ingredients are is in [...]/enc/[lang]/kitchen/:
d2a7098b 15
435d2dec 16# Script: assemble-all-pages
d2a7098b 17
435d2dec
TG
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
48c3acb0 22
435d2dec
TG
23# Includes: footer.html
24# head1.html
25# head2.html
26# javascript.html
27# translist.html
48c3acb0 28
435d2dec
TG
29# To regenerate the pages in [...]/enc/[lang]/:
30# - In the terminal, cd to [...]/enc/[lang]/kitchen/ and enter:
48c3acb0 31# $ ./assemble-all-pages
435d2dec
TG
32# - Or, in the file browser, display the directory [...]/kitchen/ (not its
33# parent) and double-click on the script.
48c3acb0
TG
34
35# And if anything goes wrong, you can do a git reset, right? ;-)
36
37# ==========================================================================
d2a7098b
TG
38
39set -e
d2a7098b
TG
40
41# Create temporary files.
42before=$(mktemp -t h2p.XXXXXX) || exit 1
43after=$(mktemp -t h2p.XXXXXX) || exit 1
48c3acb0
TG
44templates=$(mktemp -t h2p.XXXXXX) || exit 1
45list=$(mktemp -t h2p.XXXXXX) || exit 1 # includes, then deletion markers
46deletions=$(mktemp -t h2p.XXXXXX) || exit 1
47trap 'rm -f "$before" "$after" "$templates" "$list" "$deletions"' EXIT
d2a7098b
TG
48
49# List all the templates in the working directory.
48c3acb0 50if ! ls *.t.html > $templates 2>/dev/null; then
d2a7098b
TG
51 echo "There is no template in this directory." && exit 1
52fi
53
48c3acb0 54# Process each template in the list.
d2a7098b
TG
55while 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.
48c3acb0 62 cp $template ../$page && sed -i '1i\\n' ../$page
d2a7098b
TG
63
64 # List the includes.
48c3acb0
TG
65 grep '^<!-- include virtual="' ../$page |
66 sed 's%^.*include virtual="\([^"]\+\).*$%\1%' > $list
d2a7098b 67
48c3acb0 68 # Add the includes.
d2a7098b 69 while read include; do
48c3acb0
TG
70 sed "1,/^<!-- include virtual=\"$include\"/!d" ../$page > $before
71 sed "1,/^<!-- include virtual=\"$include\"/d" ../$page > $after
d2a7098b 72 if [ -f "$include" ]; then
48c3acb0 73 cat $before $include $after > ../$page
d2a7098b
TG
74 else
75 echo "$include is missing." && exit 1
76 fi
48c3acb0
TG
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
d2a7098b 99 fi
48c3acb0
TG
100 # Delete any extra blank lines at the end of the page.
101 sed -i ':a /^\n*$/ {$d; N; ba}' ../*.html
d2a7098b 102
48c3acb0 103done < $templates
d2a7098b 104exit 0