X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=doc%2Fupdt.sh;h=1c9d023eb75b3af7375afee5aa3e3fa049937dca;hb=bf9d05d3ba3c482a75cfa6aedf661f6e51728e3e;hp=cd978e228213a3a0c4dbfa21270ab948b96911ac;hpb=302353aa3b90bf3b70d33f05e6c78754d2f1bc7a;p=src%2Fapp-framework-binder.git diff --git a/doc/updt.sh b/doc/updt.sh index cd978e22..1c9d023e 100755 --- a/doc/updt.sh +++ b/doc/updt.sh @@ -1,9 +1,6 @@ -#!/bin/sh - -subst() { - awk -v pat="$1" -v rep="$(sed 's:\\:\\\\:g' $2)" '{gsub(pat,rep);gsub(pat,"\\&");print}' -} +#!/bin/bash +# the HTML template main=' @@ -14,18 +11,37 @@ GENERATED-MARKDOWN-HERE ' -for x in *.md; do - t=$(git log -n 1 --format=%ct $x) +# substitute the pattern $1 by the content of the file $2 +subst() { + awk -v pat="$1" -v rep="$(sed 's:\\:\\\\:g' $2)" '{gsub(pat,rep);gsub(pat,"\\&");print}' +} + +# update the date field of file $1 +updadate() { + local x=$1 + local t=$(git log -n 1 --format=%ct $x) [[ -n "$t" ]] || t=$(stat -c %Y $x) - d=$(LANG= date -d @$t +"%d %B %Y") + local 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 +} + +# make the html file for $1 +mkhtml() { + local x=$1 + local h=${x%%.md}.html + expand -i $x | sed 's:^ : :' > $h.pre + markdown -f toc,autolink $h.pre > $h.toc.no + markdown -Tf toc,autolink $h.pre > $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* + rm $h.* +} + +# apply +for x in *.md; do + updadate $x + mkhtml $x done