widget
[enc-live.git] / replace-lang-picker
1 #!/bin/bash
2
3 # Replace the language picker site-wide, using a common source file:
4 # "lang-picker-source". The script is called from the root of enc-live.
5 # It doesn't take an argument.
6
7 set -e
8 set -o pipefail
9
10 head=$(mktemp -t rt.XXXXXX) || exit 1
11 picker=$(mktemp -t rt.XXXXXX) || exit 1
12 tail=$(mktemp -t rt.XXXXXX) || exit 1
13 trap 'rm -f "$head" "$picker" "$tail"' EXIT
14
15 # List all HTML files with a language picker and take them one by one.
16 # The regex will select index and workshops.
17 find . -regex "\./.*/[iw][no][dr].*\.html" -not -path "./missing/*" |
18 sort | sed 's,^\./,,' | while read f; do
19 # Extract the language from the file name.
20 lang=${f%%/*}
21 # Make sure the page is correctly formatted.
22 if grep -q '<ul id="languages" class="os">' $f &&
23 grep -q '<li><strong><a href=.*Translation_Guide">' $f; then
24 # Add the 'current' class to the relevant item of lang-picker-source.
25 sed "s,<li><a href=\"/$lang\">,<li><a class=\"current\" href=\"/$lang\">," \
26 lang-picker-source > $picker
27 # Extract what's before the language picker...
28 sed -n '1,/<ul id="languages" class="os">/p' $f > $head
29 # and what follows it.
30 sed -n '/<li><strong><a href=.*Translation_Guide">/,$p' $f > $tail
31 # Assemble.
32 cat $head $picker $tail > $f
33 else
34 echo " !!! Unable to replace the language picker in $f."
35 exit 1
36 fi
37 done
38
39 # Commit the changes.
40 git add */index.html */workshops.html
41 git commit -m "index & workshops: update the language picker."