add BSD date compatibility - static-site-scripts - static site generator shellscripts
(HTM) git clone git://git.codemadness.org/static-site-scripts
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 05db9599e47099f4e2519bf59827417b5582f22b
(DIR) parent 9cdec7ec0bba8b1205aacd9cd1b9c1c3b87fde98
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Mon, 27 Jul 2015 12:17:00 +0200
add BSD date compatibility
Diffstat:
M generate.sh | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/generate.sh b/generate.sh
@@ -27,6 +27,22 @@ outputdir="output"
# Markdown processor: default: is "smu".
markdown="smu"
+#gnudate(fmt,date)
+gnudate() {
+ date "+$1" -d "$2"
+}
+
+#bsddate(fmt,date)
+bsddate() {
+ date -j "+$1" "$(printf '%s' "$2" | tr -Cd '[:digit:]')"
+}
+
+# added for compatibility with GNU and BSD date.
+alias formatdate='gnudate'
+if ! gnudate '%Y' '2015-01-01 00:00' 2>/dev/null; then
+ alias formatdate='bsddate'
+fi
+
#makeid(title), format "Some title" to "some-title".
makeid() {
printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | sed -e 's@[^a-zA-Z0-9]\+@-@g' \
@@ -190,7 +206,7 @@ while read -r meta; do
# RSS item: append.
# NOTE: GMT timezone is hard-coded because %z is not consistent,
# change accordingly.
- contentrsspubdate=$(date "+%a, %d %b %Y %H:%M:%S GMT" -d "${timeupdated}")
+ contentrsspubdate=$(formatdate "%a, %d %b %Y %H:%M:%S GMT" "${timeupdated}")
contentrss="${contentrss}$(
cat <<!__EOF__
<item>
@@ -205,8 +221,8 @@ while read -r meta; do
)"
# Atom item: append.
- contentatomupdated=$(date "+%Y-%m-%dT%H:%M:%SZ" -d "${timeupdated}")
- contentatompublished=$(date "+%Y-%m-%dT%H:%M:%SZ" -d "${timecreated}")
+ contentatomupdated=$(formatdate "%Y-%m-%dT%H:%M:%SZ" "${timeupdated}")
+ contentatompublished=$(formatdate "%Y-%m-%dT%H:%M:%SZ" "${timecreated}")
contentatom="${contentatom}$(
cat <<!__EOF__
<entry>