summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rss.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/rss.sh b/rss.sh
new file mode 100644
index 0000000..fcb4e8e
--- /dev/null
+++ b/rss.sh
@@ -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.'