aboutsummaryrefslogtreecommitdiffstats
path: root/doc/updt.sh
blob: d0c02e7add08324af9b21c350af017cb08cea7f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash

title() {
	sed '/^[ \t]*$/d' "$1" |
	sed '/^===/Q' |
	sed '/^---/Q' |
	sed 's/^# //;T;Q' |
	sed 's/^## //;T;Q' |
	sed '/^---/Q'
}

authors() {
	git log --numstat --format='A %aN' -- "$1" |
	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}' |
	sort -nr |
	sed 's/[^:]* : //' |
	sed '1!s/^/; /' |
	tr -d '\n'
}

dateof() {
	local file="$1"
	local t=$(git log -n 1 --format=%ct "$file")
	[[ -n "$t" ]] || t=$(stat -c %Y "$file")
	LANG= date -d @$t +"%d %B %Y"
}

meta() {
	local file="$1"
	local t=$(title "$file")
	local a=$(authors "$file")
	local d=$(dateof "$file")
	echo "% $t"
	echo "% $a"
	echo "% $d"
	cat "$file"
}


# make the html file for $1
mkhtml() {
  local x=$1
  local h=${x%%.md}.html
  echo updating $h from $x
  meta "$x" |
  pandoc --css doc.css -f markdown -t html5 --toc > "$h"
}

# apply
for x in *.md; do
  mkhtml $x
done