add BSD date compatibility - static-site-scripts - static site generator shells… | |
git clone git://git.codemadness.org/static-site-scripts | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 05db9599e47099f4e2519bf59827417b5582f22b | |
parent 9cdec7ec0bba8b1205aacd9cd1b9c1c3b87fde98 | |
Author: Hiltjo Posthuma <[email protected]> | |
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(-) | |
--- | |
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-… | |
@@ -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 "${timeupdate… | |
+ contentrsspubdate=$(formatdate "%a, %d %b %Y %H:%M:%S GMT" "${timeupda… | |
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> |