commit 8c2b3bddef09473c1d9a6b07d912c9903ca2f7a8
parent 3f10fb35fdae739eb66c278555860cf460592ae8
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Thu, 12 Dec 2024 10:01:40 +0100
feat: serve website icons locally
Diffstat:
4 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -5,3 +5,4 @@ centre.xml
atom.xml
rss.xml
opml.xml
+assets/site-icons/**
diff --git a/.htaccess b/.htaccess
@@ -9,9 +9,11 @@ IndexOptions +Charset=UTF-8
# Disallow browsing of certain sub-directories (redirect to 404)
RedirectMatch 404 ^/.git/.*$
+RedirectMatch 404 ^/.gitignore$
RedirectMatch 404 ^/.ssh/.*$
RedirectMatch 404 ^/.config/.*$
RedirectMatch 404 ^/.local/.*$
RedirectMatch 404 ^/.cache/.*$
RedirectMatch 404 ^/config.yaml$
RedirectMatch 404 ^/template.html$
+RedirectMatch 404 ^/*.sh
diff --git a/fetch_favicon.sh b/fetch_favicon.sh
@@ -0,0 +1,55 @@
+#!/usr/bin/env sh
+
+# fetch input config file, fall back to "general"
+if [ -z $1 ]; then
+ CONFIG="centre.yaml"
+else
+ CONFIG="$1"
+fi
+
+# read yaml file
+URLS=`grep -E "^\s*-*\ web:" "$CONFIG" | sed -e 's/^.*web:\ //g'`
+
+# get domains
+DOMAINS=`
+ echo "$URLS" | sed -E -e 's/https:\/\/([^\/]+).*$/\1/g' | sort | uniq
+`
+
+# loop through websites
+for DOMAIN in $DOMAINS; do
+
+ # User output
+ printf "Fetching favicon for ${DOMAIN}...\n"
+
+ # read HTML of webpage
+ HTML=`curl --silent --location "$DOMAIN"`
+
+ # Fetch Favicon reference from HTML
+ ICN_URI=`
+ echo "$HTML" | \
+ grep "rel=\"icon\"" | \
+ tail -n 1 | \
+ sed -E -e 's/^.*href=\"([^\"]*)\".*$/\1/'
+ `
+
+ # Post-Process favicon url in order to prepare the download
+ ICN_URL=`
+ echo "$ICN_URI" | \
+ sed -E \
+ -e "s/^\//https:\/\/$DOMAIN\//" \
+ -e "s/^(\.+)/https:\/\/$DOMAIN\/\1/"
+ `
+
+ # # Get file extension
+ # ICN_EXT=`
+ # echo "$ICN_URI" | \
+ # sed -E -e 's/^.*\.([^\.]+)$/\1/'
+ # `
+
+ # Download Favicon to assets folder
+ curl --silent --location \
+ --output "./assets/site-icons/${DOMAIN}.${ICN_EXT}" \
+ "$ICN_URL"
+
+done
+
diff --git a/run.sh b/run.sh
@@ -1,12 +1,15 @@
#!/usr/bin/env sh
-# fetch input config file, fall back to "general"
+# fetch input config file, fall back to "centre"
if [ -z $1 ]; then
CONFIG="centre.yaml"
else
CONFIG="$1"
fi
+# Re-download favicons
+source ./fetch_favicon.sh "$CONFIG" &
+
# Gather various information from config file
printf "Gather information from config file...\n"
HTML=`grep -E '^\s+file:.*?\.html\s*$' "$CONFIG" | awk '{ print $NF }'`
@@ -40,7 +43,7 @@ sed -E -e "s/<!--MANIFEST-->/\"$MANIFEST\"/" -i "$HTML"
# insert favicon image buttons
printf "Inserting favicons...\n"
-sed -E -e 's/<!--IMG\ src=\"(https:\/\/[^\/]*)[^\"]*(\"[^>]*>)-->/<img src=\"\1\/favicon.ico\2/g' -i "$HTML"
+sed -E -e 's/<!--IMG\ src=\"https:\/\/([^\/]*)[^\"]*(\"[^>]*>)-->/<img src=\"\/assets\/site-icons\/\1\2/g' -i "$HTML"
# Insert feeds list
printf "Inserting feeds list...\n"