#!/bin/bash DATE_CMD="date" # Check if the script is running on macOS if [[ "$OSTYPE" == "darwin"* ]]; then DATE_CMD="gdate" fi # Defaults source="https://discuss.privacyguides.net/top.json?period=weekly" tag="top posts" destination="./site/en/index.html" count=3 for arg in "$@" do case $arg in --source=*) source="${arg#*=}" shift ;; --tag=*) tag="${arg#*=}" shift ;; --destination=*) destination="${arg#*=}" shift ;; --count=*) count="${arg#*=}" shift ;; esac done # URL of the Discourse top.json DISCOURSE_URL="$source" # Fetch the JSON data json_data=$(curl -s $DISCOURSE_URL) # Extract the first 3 topics topics=$(echo $json_data | jq -r ".topic_list.topics[:$count]") users=$(echo $json_data | jq -r ".users") # Generate HTML for the first 3 posts html_output="" for row in $(echo "${topics}" | jq -r '.[] | @base64'); do _jq() { echo ${row} | base64 --decode | jq -r ${1} } title=$(_jq '.title') id=$(_jq '.id') like_count=$(_jq '.like_count') reply_count=$(_jq '.posts_count') views=$(_jq '.views') author_id=$(_jq '.posters[0].user_id') author_info=$(echo "${users}" | jq -r ".[] | select(.id==$author_id)") author_username=$(echo "${author_info}" | jq -r ".username") html_output+="
" html_output+="" html_output+=" ${views} " html_output+="" html_output+=" ${like_count} " html_output+="" html_output+=" ${reply_count} " html_output+="
" html_output+="