diff options
author | Tyler Davis <tyler@gluecode.net> | 2025-01-18 07:33:18 +0000 |
---|---|---|
committer | Tyler Davis <tyler@gluecode.net> | 2025-01-18 07:33:18 +0000 |
commit | 457d3721724877d4eb9c6936b5d7556007f92353 (patch) | |
tree | 235f2fd31b21b740f112c9d4b4a008b06b20734a /rss.sh | |
parent | 5261b649fee555560f7de44b6278d4dc6fcb5c9a (diff) | |
download | journal-457d3721724877d4eb9c6936b5d7556007f92353.tar.gz journal-457d3721724877d4eb9c6936b5d7556007f92353.zip |
rss: format script
Diffstat (limited to 'rss.sh')
-rwxr-xr-x[-rw-r--r--] | rss.sh | 50 |
1 files changed, 25 insertions, 25 deletions
@@ -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.' |