add muos to index
[pipapo-website/.git] / build_website.sh
1 #!/bin/bash
2 DEFAULT_CONF=page
3 GROUP=$(find -L index.txt -printf "%g")
4 CONCURRENCY_LEVEL=${CONCURRENCY_LEVEL:-3}
5 umask 003
6
7 run_menugen=no
8
9
10 # first pass, poor man dependency tracking over all .txt files
11 if [[ ! "$1" ]]; then
12         echo -n "finding dependencies "
13
14         loop=1
15         while [[ $loop = 1 ]]; do
16                 loop=0
17                 find -L . -name '*.txt' -group "$GROUP" |
18                         {
19                                 while read file; do
20                                         echo -n "."
21                                         # check for includes
22                                         sed 's/include::\([^[]*\).*/\1/p;d' "$file" | while read prerequisite; do
23                                                 if [[ "${prerequisite:1:1}" != '/' ]]; then
24                                                         prerequisite="${file%/*}/$prerequisite"
25                                                 fi
26                                                 if [[ "${prerequisite}" -nt "${file}" ]]; then
27                                                         echo -n ":"
28                                                         touch "$file"
29                                                         loop=1
30                                                 fi
31                                         done
32                                         # check for 'sys' commands
33                                         if grep 'sys[23]\?:*\[.*\]' "$file" >/dev/null; then
34                                                 echo -n "+"
35                                                 touch "$file"
36                                         fi
37                                 done
38                                 if [[ $loop = 1 ]]; then
39                                         false
40                                 fi
41                         }
42
43                 loop=$?
44         done
45 echo
46 fi
47
48
49 # second pass for every .txt file
50 echo -n "processing files "
51 case "$1" in
52 --all|'')
53         find -L . -name '*.txt' -group "$GROUP"
54         ;;
55 *)
56         for file in "$@"; do
57                 echo "$file"
58         done
59         ;;
60 esac |
61         {
62         echo >.todo.$$
63         while read file; do
64                 echo -n "." >&2
65                 # when the .txt is newer than an existing .html
66                 if [[ -w . && "$file" -nt "${file%*.txt}.html" || "$1" ]]; then
67                         # use the default config file
68                         conf="${DEFAULT_CONF}.conf"
69                         # or if there is a .conf file with the same basename as the .txt file use that instead
70                         if [[ -e "${file%*.txt}.conf" ]]; then
71                                 conf="${file%*.txt}.conf"
72                         fi
73                         # run asciidoc over it
74                         echo "asciidocing $file" >&2
75                         printf "%q " --unsafe --backend=xhtml11 \
76                                         --attribute icons --attribute=iconsdir=/images/asciidoc \
77                                         --attribute=badges! --attribute quirks! \
78                                         --conf-file="${conf}" \
79                                         "$file" >>.todo.$$
80                         echo >>.todo.$$
81                         #
82                         # note we did set       --attribute=revision="$VERS"  --attribute=date="$DATE"
83                         # IMHO it is better to use the date hard wired in the documents (2/11, Ichthyo)
84                         echo >&2
85
86                         run_menugen=yes
87                 fi
88         done
89
90         xargs -P $CONCURRENCY_LEVEL -r -n 10 -a .todo.$$ asciidoc
91         rm .todo.$$
92
93         if [[ $run_menugen = yes ]]; then
94                 ./menugen.py -p -s -w >menu.html.tmp
95                 if cmp -s menu.html.tmp menu.html; then
96                         rm menu.html.tmp
97                 else
98                         echo
99                         echo "regenerate menus"
100                         mv menu.html.tmp menu.html
101                 fi
102         fi
103         }
104 echo
105