#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"
TESTIMONIALS_JSON_URL="https://data.nhcarrigan.com/testimonials.json"
TESTIMONIALS_JSON_FILE="testimonials.json"
TESTIMONIALS_HTML_FILE="testimonials/index.html"
# Templating
HTML_START='
Testimonials
Testimonials
See what our past clients have to say about our work!
Want to submit your own? Use our web form.
'
# Fetch the latest testimonials.json
curl -sSL "$TESTIMONIALS_JSON_URL" -o "$TESTIMONIALS_JSON_FILE"
# Convert JSON to HTML, sorted by date descending (newest first)
TESTIMONIALS_HTML=$(jq -r '
def parse_date:
split(" ") |
.[2] + "-" +
(.[1] |
if . == "January" then "01"
elif . == "February" then "02"
elif . == "March" then "03"
elif . == "April" then "04"
elif . == "May" then "05"
elif . == "June" then "06"
elif . == "July" then "07"
elif . == "August" then "08"
elif . == "September" then "09"
elif . == "October" then "10"
elif . == "November" then "11"
elif . == "December" then "12"
else . end
) + "-" +
(.[0] | if length == 1 then "0" + . else . end);
sort_by(.date | parse_date) | reverse |
.[] |
"\n
" + .name + "
\n
" + .content + "
\n
" + .date + "
\n
"
' "$TESTIMONIALS_JSON_FILE")
# Create temporary file with the HTML content
echo "$HTML_START" > "$TESTIMONIALS_HTML_FILE"
echo "$TESTIMONIALS_HTML" >> "$TESTIMONIALS_HTML_FILE"
echo "$HTML_END" >> "$TESTIMONIALS_HTML_FILE"
echo "Testimonials updated in $TESTIMONIALS_HTML_FILE"
# Clean up
rm "$TESTIMONIALS_JSON_FILE"