diff options
author | ben <ben@nagy.contact> | 2025-01-10 11:14:29 -0800 |
---|---|---|
committer | ben <ben@nagy.contact> | 2025-01-10 11:14:29 -0800 |
commit | fb4f206e21cc2853e904e8e548b3d4450b208c8d (patch) | |
tree | 92044e436174b598bbb831473412ee4382a05396 /scripts/archive/blog/rss-parse.sh | |
parent | 7339a5dae5f48ba37d44094f8aaa9915695f86e5 (diff) |
added scriptsmain
Diffstat (limited to 'scripts/archive/blog/rss-parse.sh')
-rwxr-xr-x | scripts/archive/blog/rss-parse.sh | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/archive/blog/rss-parse.sh b/scripts/archive/blog/rss-parse.sh new file mode 100755 index 0000000..9f635d4 --- /dev/null +++ b/scripts/archive/blog/rss-parse.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +[ ! -f "$1" ] && + echo "Give \`sup\` a page which has been added/updated." && + exit 1 + +website="https://domain.com" +rssfile="../rss/blog.xml" +replchar='^' + +link="$website/$1" +title="$(sed -n 's/<title>\(.*\)<\/title>/\1/Ip' "$1")" + +if grep -q "<guid.*>$link</guid>" "$rssfile"; then + guid="$link#$(date '+%y%m%d%H%M%S')" + title="$title (Updated)" + echo "Explain the nature of the update:" + read -r content + [ -z "$content" ] && content="New updates to $link" +else + + guid=$link + content="$(tr '\n' $replchar < "$1" | sed " + s/.*<body>// + s/<footer>.*<\/footer>// + s/<nav>.*<\/nav>// + s/<\/body>.*// + " | tr -s $replchar '\n')" +fi + +rssdate="$(LC_TIME=en_US date '+%a, %d %b %Y %H:%M:%S %z')" + +temp="$(mktemp)"; +trap 'rm -f "$temp"' 0 1 2 3 15 +echo " +<item> +<title>$title</title> +<guid>$guid</guid> +<link>$link</link> +<pubDate>$rssdate</pubDate> +<description><![CDATA[$content +]]></description> +</item> +" > "$temp" + +sed -i "/<!-- rss -->/r $temp" "$rssfile" |