X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=doc%2Fupdt.sh;h=5267ad5f26d69c4fd122e31c156208c0e75a55ac;hb=9c4961a0e68458061171aef5f3b30a9b1fa8e333;hp=cd978e228213a3a0c4dbfa21270ab948b96911ac;hpb=302353aa3b90bf3b70d33f05e6c78754d2f1bc7a;p=src%2Fapp-framework-binder.git diff --git a/doc/updt.sh b/doc/updt.sh index cd978e22..5267ad5f 100755 --- a/doc/updt.sh +++ b/doc/updt.sh @@ -1,31 +1,52 @@ -#!/bin/sh +#!/bin/bash -subst() { - awk -v pat="$1" -v rep="$(sed 's:\\:\\\\:g' $2)" '{gsub(pat,rep);gsub(pat,"\\&");print}' +title() { + sed '/^[ \t]*$/d' "$1" | + sed '/^===/Q' | + sed '/^---/Q' | + sed 's/^# //;T;Q' | + sed 's/^## //;T;Q' | + sed '/^---/Q' } -main=' - - - - - -GENERATED-MARKDOWN-HERE - -' +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 + meta "$x" | + pandoc --css doc.css -f markdown -t html5 --toc > "$h" +} +# apply for x in *.md; do - t=$(git log -n 1 --format=%ct $x) - [[ -n "$t" ]] || t=$(stat -c %Y $x) - d=$(LANG= date -d @$t +"%d %B %Y") - sed -i "s/^\( Date: *\).*/\1$d/" $x - h=${x%%.md}.html - markdown -f toc,autolink $x > $h.toc.no - markdown -Tf toc,autolink $x > $h.toc.yes - head --bytes=-$(stat -c %s $h.toc.no) $h.toc.yes > $h.toc - echo "$main" | - subst GENERATED-MARKDOWN-HERE $h.toc.no | - subst TABLE-OF-CONTENT-HERE $h.toc > $h -# rm $h.toc* + mkhtml $x done