From 51265f08cb9b19ebb01375d05057fdbc338b6355 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 12 Dec 2024 17:07:16 +0800 Subject: add build for rss feeds --- www/Makefile | 11 ++++++++--- www/scripts/update-feeds.sh | 28 ++++++++++++++++++++++++++++ www/templates/header.html | 5 +---- 3 files changed, 37 insertions(+), 7 deletions(-) create mode 100755 www/scripts/update-feeds.sh (limited to 'www') diff --git a/www/Makefile b/www/Makefile index 699abb2..d54081b 100644 --- a/www/Makefile +++ b/www/Makefile @@ -4,10 +4,15 @@ ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) # build html files for public/ build: cd $(ROOT_DIR) - @input_dir=~/log/public \ - output_dir=/srv/http \ - scripts/build.sh + export input_dir=~/log/public + export output_dir=/srv/http + @scripts/build.sh # Migrage frontmatter from '---' to HTML comment '' frontmatter: find content -type f -name '*.md' | xargs sed -i ':frontmatter { 1s/^---//; 1!b}; /^---/ {1b frontmatter}' + +rss: + cd /srv/rss + export LIST=~/log/public/links/rss.list + $(ROOT_DIR)/scripts/update-feeds.sh diff --git a/www/scripts/update-feeds.sh b/www/scripts/update-feeds.sh new file mode 100755 index 0000000..8dff837 --- /dev/null +++ b/www/scripts/update-feeds.sh @@ -0,0 +1,28 @@ +#! /bin/bash + +cd /srv/rss +mkdir -p feeds + +LIST=${LIST:?} +curlOpts='--insecure' + +cat "${LIST}" | while read url interval tags; do + feed=feeds/${url//\//%2F} + unset next_fetch; declare -i next_fetch=0 + + # Get time of next fetch + if [ -f $feed ]; then + interval=$(<<<"$interval" sed 's/m/minute/; s/h/hour/; s/d/day/;') + next_fetch=$(date -d "$(date -r $feed) + $interval" +'%s') + fi + + # Do not fetch feed if interval covers current time + [ $(date +'%s') -lt $next_fetch ] && continue + + # Set limit of HTTP connections + while [ $(jobs -p | wc -l) -ge 10 ]; do + sleep 0.5; + done + + curl -s $curlOpts $url -o $feed || echo Fail to fetch $url >&2 & +done diff --git a/www/templates/header.html b/www/templates/header.html index a77079a..d5975fd 100644 --- a/www/templates/header.html +++ b/www/templates/header.html @@ -4,10 +4,7 @@ About | Posts | Projects | - - Links + Links