summaryrefslogtreecommitdiffstats
path: root/doc/updt.sh
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2016-05-28 11:55:08 +0200
committerFulup Ar Foll <fulup@iot.bzh>2016-05-28 11:55:08 +0200
commit1a66f6a8c0b213e14bc0b1896bfaa68a5c2a5002 (patch)
tree0f84cd21a3fd393bddcab603d2452c84c97defa6 /doc/updt.sh
parentfcdb6bb4b88510614f5eb96545ea724ce442d606 (diff)
parenteaab2fbbed4601415b5be052b39a0c0df11fdc38 (diff)
Merge branch 'master' of https://github.com/iotbzh/afb-daemon
Diffstat (limited to 'doc/updt.sh')
-rwxr-xr-xdoc/updt.sh40
1 files changed, 28 insertions, 12 deletions
diff --git a/doc/updt.sh b/doc/updt.sh
index cd978e22..af64e31e 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='<html>
<head>
<link rel="stylesheet" type="text/css" href="doc.css">
@@ -14,18 +11,37 @@ GENERATED-MARKDOWN-HERE
</body>
</html>'
-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