summaryrefslogtreecommitdiffstats
path: root/rss.sh
diff options
context:
space:
mode:
Diffstat (limited to 'rss.sh')
-rwxr-xr-x[-rw-r--r--]rss.sh50
1 files changed, 25 insertions, 25 deletions
diff --git a/rss.sh b/rss.sh
index fcb4e8e..5cd9ef4 100644..100755
--- a/rss.sh
+++ b/rss.sh
@@ -3,39 +3,39 @@ 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
+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)
+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
+ # Add the posts to the XML file
+ echo '<item>' >>blog.xml
+ echo "<title>$post_title</title>" >>blog.xml
+ echo "<link>https://www.gluecode.net/blog/$post_id</link>" >>blog.xml
+ echo "<guid>https://www.gluecode.net/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 '</channel>' >>blog.xml
+echo '</rss>' >>blog.xml
echo 'RSS blog feed generated successfully.'