commit 803b8dc06676219ba6cced648e33538bb6520de0
parent ccc1b19aaad3e3eb1c7967e6357b13beb0e426a9
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Wed, 19 Mar 2025 20:55:54 +0100
fix: smaller issues within the rewrite functionality
Diffstat:
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/fetch_and_rewrite.sh b/fetch_and_rewrite.sh
@@ -3,10 +3,14 @@
# Config -----------------------------------------------------------------------
# cache directory
-cache_dir="/tmp/cache/newsplanet/rewrite"
+cache_dir="/tmp/newsplanet/rewrites"
file_name=$(echo "$1" | sed -e 's/https*:\/\///' -e 's/\//_/g')
cache_file="${cache_dir}/${file_name}"
+# ensure all required directories exist
+mkdir -p ./rewrites/
+mkdir -p "${cache_dir}"
+
# Function ---------------------------------------------------------------------
read_xml () {
@@ -18,7 +22,9 @@ write_xml () {
cat ${1} | sed -E \
-e 's/^(\/.*$)/<\1>/g' \
-e 's/^([^<].*)\s*=>\s*(.*$)/<\1>\2/g' \
- -e 's/^([^<]+$)/<\1>/g' | \
+ -e 's/^([^<]+$)/<\1>/g' \
+ -e 's/\s+(\/)>/\1>/g' \
+ -e '/^[[:space:]]*$/d' | \
tee ${2} > /dev/null
}
@@ -40,6 +46,12 @@ while read_xml; do
fi
done < "${cache_file}" | tee "${cache_file}.new" > /dev/null
+# ensure that new file has closing </rss>
+if [ $(grep -e "^rss" -c "${cache_file}.new") -gt 0 ] &&
+ [ $(grep -e "^/rss" -c "${cache_file}.new") -eq 0 ]; then
+ echo "/rss" >> "${cache_file}.new"
+fi
+
# compare old to new file
if [ -f "${cache_file}.old" ]; then