aboutsummaryrefslogtreecommitdiff
path: root/www/publish.sh
diff options
context:
space:
mode:
Diffstat (limited to 'www/publish.sh')
-rwxr-xr-xwww/publish.sh47
1 files changed, 26 insertions, 21 deletions
diff --git a/www/publish.sh b/www/publish.sh
index f9aabf3e..9a8a6abc 100755
--- a/www/publish.sh
+++ b/www/publish.sh
@@ -1,7 +1,8 @@
-#!/bin/bash
+#!/usr/bin/env bash
#
# Copyright (C) 2017 Alyssa Rosenzweig <alyssa@rosenzweig.io>
# Copyright (C) 2017 Leah Rowe <info@minifree.org>
+# Copyright (C) 2017 Michael Reed <michael@michaelreed.io>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -19,14 +20,16 @@
[ "x${DEBUG+set}" = 'xset' ] && set -v
set -e
-echo $1
FILE=${1%.md}
+TMPFILE=$(mktemp -t libreboot_www.XXXXXXXXXX)
-cat $1 > temp.md
+cat "$1" > "$TMPFILE"
OPTS="-T Libreboot"
-if [ "${FILE}" != "./index" ]; then
+if [[ $FILE == "index" || $FILE == "./index" ]]; then
+ OPTS="--css /headercenter.css"
+else
if [[ $FILE == *suppliers ]]
then
RETURN=""
@@ -41,38 +44,40 @@ if [ "${FILE}" != "./index" ]; then
RETURN="<strong><a href='/git.html#editing-the-website-and-documentation-wiki-style'>Edit this page</a></strong> -- <a href='$DEST'>Back to previous index</a>"
OPTS="-T Libreboot"
fi
-else
- OPTS="--css /headercenter.css"
fi
if [[ $FILE = *suppliers ]]; then
- printf "\n<strong><a href=\"/git.html#editing-the-website-and-documentation-wiki-style\">Edit this page</a></strong> -- <a href=\"../\">Back to previous page</a>\n" >> temp.md
+ printf '\n%s\n' "<strong><a href=\"/git.html#editing-the-website-and-documentation-wiki-style\">Edit this page</a></strong> -- <a href=\"../\">Back to previous page</a>" >> "$TMPFILE"
fi
-if [ "${FILE}" != "./docs/fdl-1.3" ] && [ "${FILE}" != "./conduct" ]; then
- cat footer.md >> temp.md
+if [[ $FILE != "./docs/fdl-1.3" && $FILE != "docs/fdl-1.3" &&
+ $FILE != "./conduct" && $FILE != "conduct" ]]; then
+ cat footer.md >> "$TMPFILE"
fi
# change out .md -> .html
-sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g'
-sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g'
+sed -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g' "$TMPFILE"
+sed -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g' "$TMPFILE"
# change out .md -> .html
-sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g'
-sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g'
+sed -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g' "$TMPFILE"
+sed -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g' "$TMPFILE"
# work around issue #2872
-TOC=$(grep -q "^x-toc-enable: true$" temp.md && echo "--toc --toc-depth=2") || TOC=""
+TOC=$(grep -q "^x-toc-enable: true$" "$TMPFILE" && printf '%s\n' "--toc --toc-depth=2") || TOC=""
# work around heterogenous pandoc versions
-SMART=$(pandoc -v | grep -q '2\.0' || echo "--smart") || SMART=""
+SMART=$(pandoc -v | grep -q '2\.0' || printf '%s\n' "--smart") || SMART=""
# chuck through pandoc
-pandoc $TOC $SMART temp.md -s --css /global.css $OPTS \
- --template template.html --metadata return="$RETURN"> $FILE.html
-
-# additionally, produce bare file for RSS
-pandoc $1 > $FILE.bare.html
+#
+# $OPTS must not be quoted, otherwise pandoc interprets '--css /headercenter.css'
+# as one argument, when it is actually two.
+pandoc $TOC $SMART "$TMPFILE" -s --css /global.css $OPTS \
+ --template template.html --metadata return="$RETURN" > "$FILE.html"
# generate section title anchors as [link]
-sed $FILE.html -i -e 's_^<h\([123]\) id="\(.*\)">\(.*\)</h\1>_<div class="h"><h\1 id="\2">\3</h\1><a aria-hidden="true" href="#\2">[link]</a></div>_'
+sed -i -e 's_^<h\([123]\) id="\(.*\)">\(.*\)</h\1>_<div class="h"><h\1 id="\2">\3</h\1><a aria-hidden="true" href="#\2">[link]</a></div>_' "$FILE.html"
+
+# clean up temporary file
+rm -f "$TMPFILE"