summaryrefslogtreecommitdiffstats
path: root/doc/updt.sh
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-05-29 10:11:06 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-05-29 10:15:53 +0200
commitf45bd5fbf8d1fe440b1855d93b387755d63ac8f0 (patch)
tree5112f5cd031d1c4a3d2719a37c8b32db7a9a5a66 /doc/updt.sh
parent42888438a490f0ce28376b33b4d87c46008209bf (diff)
improves documentation formatting
Change-Id: I819dfdc98dab5fc75c8858b2afb1484e8d6b3b5a Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'doc/updt.sh')
-rwxr-xr-xdoc/updt.sh46
1 files changed, 34 insertions, 12 deletions
diff --git a/doc/updt.sh b/doc/updt.sh
index a6292c8..1c9d023 100755
--- a/doc/updt.sh
+++ b/doc/updt.sh
@@ -1,25 +1,47 @@
-#!/bin/sh
+#!/bin/bash
-fmd() {
-cat << EOC
-<html>
+# the HTML template
+main='<html>
<head>
<link rel="stylesheet" type="text/css" href="doc.css">
<meta charset="UTF-8">
</head>
<body>
-$(cat)
+GENERATED-MARKDOWN-HERE
</body>
-</html>
-EOC
+</html>'
+
+# 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)
+ local d=$(LANG= date -d @$t +"%d %B %Y")
+ sed -i "s/^\( Date: *\).*/\1$d/" $x
}
+# 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.*
+}
+# apply
for x in *.md; do
- t=$(stat -c %Y $x)
- t=$(git log -n 1 --format=%ct $x)
- d=$(LANG= date -d @$t +"%d %B %Y")
- sed -i "s/^\( Date: *\).*/\1$d/" $x
- markdown -f toc,autolink $x | fmd > ${x%%.md}.html
+ updadate $x
+ mkhtml $x
done