Introduction
This article describe three different ways of letting readers know, that a new article has been published - A simple RSS feed - App notifications using Gotify, bash and cron - E-mails using a seperate microservice
RSS
One option is to setup a XML feed of post for RSS readers
App notification
This solution uses Gotify triggered by a bash script running in cron. The user must install the Gotify app and the instance must also be avialable outside of LAN, if not you will recieve notification, when connected to LAN.
Here is the bash script
#!/bin/bash
# Load gotify token from .env
if [ -f ".env" ]; then
source .env
else
echo "Error: .env file not found."
exit 1
fi
# ---------------- CONFIG ----------------
DIR="."
# uses a simple text file to persist the number articles
# writes number of files to txt file on script end, next run start by checking n of files
# if the number of files are different from last time
COUNT_FILE="$DIR/count.txt"
GOTIFY_URL="http://192.168.0.37:2222"
#GOTIFY_TOKEN= loaded from .env
PRIORITY=5
# ----------------------------------------
[[ -f "$COUNT_FILE" ]] || echo 0 > "$COUNT_FILE"
previous_count=$(cat "$COUNT_FILE")
current_count=$(find "$DIR" -maxdepth 1 -name "*.md" -type f | wc -l)
if [[ "$current_count" -ne "$previous_count" ]]; then
latest_file=$(find "$DIR" -maxdepth 1 -name "*.md" -type f \
-printf '%T@ %f\n' | sort -n | tail -n 1 | cut -d' ' -f2-)
# Send post request to gotify instance
curl -s --max-time 5 -X POST \
"$GOTIFY_URL/message?token=$GOTIFY_TOKEN" \
-F "title=New article on rasmusbendtsen.dk" \
-F "message=Article title: ${latest_file:-None}" \
-F "priority=$PRIORITY" >/dev/null
echo "$current_count" > "$COUNT_FILE"
fi