summaryrefslogtreecommitdiff
path: root/md.sh
diff options
context:
space:
mode:
Diffstat (limited to 'md.sh')
-rwxr-xr-xmd.sh56
1 files changed, 26 insertions, 30 deletions
diff --git a/md.sh b/md.sh
index afdce35..86de05b 100755
--- a/md.sh
+++ b/md.sh
@@ -1,10 +1,10 @@
#!/bin/sh
set -e
-# usage:
-# ./md.sh <target dir>
-# ./md.sh <input md> <output html>
-#
+usage="usage:
+ ./md.sh <target dir>
+ ./md.sh <input md> <output html>"
+
# input: <target dir>/src.md ./md-header ./md-footer <site root>/nav.html
# output: <target dir>/index.html
# dependencies: lowdown fzf ./urlencode
@@ -30,21 +30,17 @@ OUT="$1/index.html"
[ "$2" ] && { IN="$1" ; OUT="$2" ; }
-[ "$1" ] || {
-echo "usage:
- ./md.sh <target dir>
- ./md.sh <input md> <output html>" ; exit 1 ;
-}
+[ "$1" ] || { echo "$usage" ; exit 1 ; }
-[ -f $IN ] || { echo "---- [FATAL] $IN not found ----" ; exit 1 ; }
-[ -f md-header ] || { echo "---- [FATAL] md-header not found ----" ; exit 1 ; }
-[ -f md-footer ] || { echo "---- [FATAL] md-footer not found ----" ; exit 1 ; }
-[ $(which lowdown) ] || { echo "---- [FATAL] lowdown not found ----" ; exit 1 ; }
+[ -f $IN ] || { printf "%s \tFATAL: %s not found\n" "[->]" "$IN"; exit 1 ; }
+[ -f md-header ] || { printf "%s \tFATAL: md-header not found\n" "[->]" ; exit 1 ; }
+[ -f md-footer ] || { printf "%s \tFATAL: md-footer not found\n" "[->]" ; exit 1 ; }
+[ $(which lowdown) ] || { printf "%s \tFATAL: lowdown not found\n" "[->]" ; exit 1 ; }
cat md-header > $OUT
lowdown -Thtml $IN >> $OUT
cat md-footer >> $OUT
-echo '[ok] initial assembly'
+printf "[ok] \tinitial assembly\n"
sedesc() {
@@ -66,30 +62,30 @@ decode() {
TITLE=$(grep -e '^title: ' -m 1 $IN | cut -f 2- -d ' ' | sedesc)
sed "s/<title>#/<title>${TITLE} \&mdash\; DistressNetwork°/1" -i'' $OUT
-printf '[ok] title: %s\n' "$(echo "$TITLE" | unesc)"
+printf "[ok] \ttitle: %s\n" "$(echo "$TITLE" | unesc)"
BOMBER=$(grep -e '^bomber: ' -m 1 $IN | cut -f 2- -d ' ' | sedesc)
sed "s/<div class=\"bomber\">#/<div class=\"bomber\">${BOMBER}/1" -i'' $OUT
-printf '[ok] bomber: %s\n' "$(echo "$BOMBER" | unesc)"
+printf "[ok] \tbomber: %s\n" "$(echo "$BOMBER" | unesc)"
MDATE=$(stat -c '%y' $IN | sed -e 's/\.[0-9]* //' -e 's/\(..\)\(..\)$/\1:\2/') # format: "yyyy-mm-dd hh:mm:ss±zz:zz" (ISO 8601)
DATE=$(echo $MDATE | cut -f 1 -d ' ' | sed -e 's/-//g' -e 's/^..//') # format: "yymmdd" (for humans)
sed "s;<div class=\"ident\"><time>#;<div class=\"ident\"><time datetime=\"${MDATE}\">${DATE};1" -i'' $OUT
sed "/^<\/head>/i <meta http-equiv=\"last-modified\" content=\"${MDATE}\" />" -i'' $OUT
-printf '[ok] date: %s (%s)\n' "$DATE" "$MDATE"
+printf "[ok] \tdate: %s (%s)\n" "$DATE" "$MDATE"
LEADING=$(grep -e '^leading: ' -m 1 $IN | cut -f 2- -d ' ' | sedesc)
sed "s;<div class=\"leading\">#;<div class=\"leading\">${LEADING};1" -i'' $OUT
-printf '[ok] leading: %s\n' "$(echo "$LEADING" | unesc)"
+printf "[ok] \tleading: %s\n" "$(echo "$LEADING" | unesc)"
METADESC="\&laquo\;${BOMBER}\&raquo\; \&mdash\; ${LEADING}"
sed "s;<meta name=\"description\" content=\"#;<meta name=\"description\" content=\"${METADESC};1" -i'' $OUT
-printf '[ok] meta description\n'
+printf "[ok] \tmeta description\n"
if [ -f $(echo $IN | cut -f 1 -d /)/nav.html ] ; then
NAVLINE=$(grep -n '<nav>' $OUT | cut -f 1 -d :) ;
sed "${NAVLINE}r $(echo $OUT | cut -f 1 -d /)/nav.html" -i'' $OUT ;
-printf '[ok] sitemap\n' ;
+printf "[ok] \tsitemap\n" ;
fi
[ "$(grep -n '<p><img' $OUT)" ] && {
@@ -102,10 +98,10 @@ while IFS='' read -r data ; do
if [ "$CAPT" = "#tex" ] ; then # for tex figures: only remove caption and containers
sed "${LINE}s;.*;<figure><img src=\"${FILE}\" alt=\"\"></figure>;" -i'' $OUT ;
- printf '[ok] tex figure at line %s\n' "$LINE" ;
+ printf "[ok] \ttex figure at line %s\n" "$LINE" ;
else
sed "${LINE}s;.*;<figure><a href=\"${FILE}\"><img src=\"${FILE}\" alt=\"\"></a><figcaption><p>${CAPT}</p></figcaption></figure>;" -i'' $OUT ;
- printf '[ok] image at line %s\n' "$LINE" ;
+ printf "[ok] \timage at line %s\n" "$LINE" ;
fi
done
@@ -114,8 +110,8 @@ done
toc() {
-[ "$(which fzf)" ] || { echo "[warning] fzf not found, skipping toc" ; return ; }
-[ -f ./urlencode ] || { echo "[warning] urlencode not found, skipping toc" ; return ; }
+[ "$(which fzf)" ] || { printf "[warn] \tfzf not found, skipping toc\n" ; return ; }
+[ -f ./urlencode ] || { printf "[warn] \turlencode not found, skipping toc\n" ; return ; }
tmp=$(mktemp -p /tmp) # using a tempfile, more convenient for storage and operations
@@ -140,7 +136,7 @@ cat $tmp | while IFS='' read -r data ; do
IDLINE=$(grep -ne "^<h[[:digit:]] id=" $OUT | fzf -f "$(echo $HEADER | unesc)" | head -n 1 | cut -f 1 -d :) ;
if [ "$IDLINE" ] ; then
sed -e "${IDLINE}s;id=\".*\">.*</h;id=\"${ID}\">${HEADER}</h;" -i'' $OUT ;
- printf ' assembled header: %s\n' "$(echo $HEADER | unesc)" ;
+ printf "\tassembled header: %s\n" "$(echo $HEADER | unesc)" ;
fi ;
done
@@ -156,7 +152,7 @@ sed "${TOCLINE}r $tmp" -i'' $OUT
rm $tmp # cleanup
-echo '[ok] table of contents'
+printf "[ok] \ttable of contents\n"
}
@@ -171,22 +167,22 @@ case "$opts" in
(*[Ff]*)
sed "/^<footer>/,/^<\/footer>/d" -i'' $OUT
- echo "[ok] footerless"
+ printf "[ok] \tfooterless\n"
opts=$(echo $opts | sed 's/[Ff]//g')
;;
(*[Hh]*)
sed "/^<header>/,/^<\/header>/d" -i'' $OUT
sed "/bg.js/d" -i'' $OUT
- echo "[ok] headerless"
+ printf "[ok] \theaderless\n"
opts=$(echo $opts | sed 's/[Hh]//g')
;;
(*)
- echo "[warning] metadata: unrecognized option(s) \"${opts}\""
+ printf "[warn] \tmetadata: unrecognized option(s) \"$s\"\n" "${opts}"
;;
esac
done
-echo "---- build complete: ${OUT} ----"
+printf "%s \tbuild complete: %s\n" "[->]" "$OUT"