add documentation & ideas about config.xml
[src/app-framework-main.git] / doc / updt.sh
1 #!/bin/bash
2
3 title() {
4         sed '/^[ \t]*$/d' "$1" |
5         sed '/^===/Q' |
6         sed '/^---/Q' |
7         sed 's/^# //;T;Q' |
8         sed 's/^## //;T;Q' |
9         sed '/^---/Q'
10 }
11
12 authors() {
13         git log --numstat --format='A %aN' -- "$1" |
14         awk '$1=="A"{sub(/^A /,"");a=$0; s[a]+=0; next}NF==3{s[a]+=($1+0)}END{for(a in s)print s[a]" : "a}' |
15         sort -nr |
16         sed 's/[^:]* : //' |
17         sed '1!s/^/; /' |
18         tr -d '\n'
19 }
20
21 dateof() {
22         local file="$1"
23         local t=$(git log -n 1 --format=%ct "$file")
24         [[ -n "$t" ]] || t=$(stat -c %Y "$file")
25         LANG= date -d @$t +"%d %B %Y"
26 }
27
28 meta() {
29         local file="$1"
30         local t=$(title "$file")
31         local a=$(authors "$file")
32         local d=$(dateof "$file")
33         echo "% $t"
34         echo "% $a"
35         echo "% $d"
36         cat "$file"
37 }
38
39
40 # make the html file for $1
41 mkhtml() {
42   local x=$1
43   local h=${x%%.md}.html
44   echo updating $h from $x
45   meta "$x" |
46   pandoc --css doc.css -f markdown -t html5 --toc > "$h"
47 }
48
49 # apply
50 for x in *.md; do
51   mkhtml $x
52 done
53