diff options
author | Tyler Davis <tyler@gluecode.net> | 2025-01-17 16:16:14 +0000 |
---|---|---|
committer | Tyler Davis <tyler@gluecode.net> | 2025-01-17 16:16:14 +0000 |
commit | 5261b649fee555560f7de44b6278d4dc6fcb5c9a (patch) | |
tree | 64aa2becea31a9d08d567876a1c710210a631060 /rss.sh | |
parent | ab492bb241d4a2533b8caa7bd5f1b8dbc969ddf2 (diff) | |
download | journal-5261b649fee555560f7de44b6278d4dc6fcb5c9a.tar.gz journal-5261b649fee555560f7de44b6278d4dc6fcb5c9a.zip |
rss: add script, untested
Diffstat (limited to 'rss.sh')
-rw-r--r-- | rss.sh | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +# RSS feed header +echo '<?xml version="1.0" encoding="UTF-8" ?>' > blog.xml +echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom>' >> blog.xml +echo '<channel>' >> blog.xml +echo '<title>RSS feed title</title>' >> blog.xml +echo '<link>https://www.example.com</link>' >> blog.xml +echo '<description>Example RSS feed </description>' >> blog.xml +echo '<language>en-us</language>' >> blog.xml +echo '<atom:link href="https://www.example.org/blog.xml" rel="self" type="application/rss+xml"/>' >> blog.xml + +# Directory containing HTML blog posts +posts_directory="/blog" + +# Parse HTML files in the directory + for filename in "$posts_directory"/*.html; do + if [ -f "$filename" ]; then + post_title=$(awk -F'<h1>|</h1>' '/<h1>/ {print $2; exit}' "$filename") + post_date=$(awk -F'<time>|</time>' '/<time>/ {print $2; exit}' "$filename") + post_content=$(sed -n '/<article>/,/<\/article>/p' "$filename" | sed '/^$/d' | tr -s ' ') + post_id=$(basename "$filename" .html) + +# Add the posts to the XML file + echo '<item>' >> blog.xml + echo "<title>$post_title</title>" >> blog.xml + echo "<link>https://www.example.com/blog/$post_id</link>" >> blog.xml + echo "<guid>https://www.example.com/blog/$post_id</guid>" >> blog.xml + echo "<pubDate>$post_date</pubDate>" >> blog.xml + echo "<description><![CDATA[$post_content]]></description>" >> blog.xml + echo '</item>' >> blog.xml + fi +done + +# Close the RSS feed +echo '</channel>' >> blog.xml +echo '</rss>' >> blog.xml + +echo 'RSS blog feed generated successfully.' |