blog

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 080d7b5894ca30c1e0b3f6cb22ebfc99bb867120
parent a3b39797d96db8e33eac0dd3e0fb48d6e79686ff
Author: Andrew Laack <andrew@laack.co>
Date:   Sun, 28 Sep 2025 14:42:53 -0500

Added rss feed logic

Diffstat:
Aposts/site/feed.xml | 20++++++++++++++++++++
Mposts/site/index.html | 2++
Mscripts/convert.sh | 62+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/posts/site/feed.xml b/posts/site/feed.xml @@ -0,0 +1,20 @@ +<?xml version='1.0' encoding='UTF-8'?> +<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'> +<channel> +<title>Andrew's Blog</title> +<link>https://blog.laack.co</link> +<description>Latest posts from Andrew's blog</description> +<language>en-us</language> +<managingEditor>andrew@laack.co</managingEditor> +<webMaster>andrew@laack.co</webMaster> +<lastBuildDate>Sun, 28 Sep 2025 14:42:22 -0500</lastBuildDate> +<atom:link href='https://blog.laack.co/feed.xml' rel='self' type='application/rss+xml'/> +<item> +<title><![CDATA[The Sustainability of YouTube]]></title> +<link>https://blog.laack.co/the-sustainability-of-youtube.html</link> +<description><![CDATA[I dislike using cloud services because they may discontinue my service [1] or they may do something stupid [2] that negatively impacts me. These concerns, along with concerns about privacy [3], have led me to keep information and content I care about away from cloud services. This does make me wonder, how many people would be distraught about the loss of their content if YouTube terminated their accounts? This is not the topic today, nor is it something I can easily answer, but it is something I wonder about and would like others to consider.]]></description> +<pubDate>2025/9/28</pubDate> +<guid>https://blog.laack.co/the-sustainability-of-youtube.html</guid> +</item> +</channel> +</rss> diff --git a/posts/site/index.html b/posts/site/index.html @@ -4,9 +4,11 @@ <meta charset='UTF-8'> <title>Andrew's Blog</title> <link rel='stylesheet' href='style.css'> +<link rel='alternate' type='application/rss+xml' title='RSS Feed' href='feed.xml'> </head> <body> <h1>Blog Posts</h1> +<p><a href='feed.xml'>RSS Feed</a></p> <ol> <li><a href='the-sustainability-of-youtube.html'>the-sustainability-of-youtube</a> - <em>2025/9/28</em></li> </ol> diff --git a/scripts/convert.sh b/scripts/convert.sh @@ -1,5 +1,10 @@ #!/bin/bash +BLOG_TITLE="Andrew's Blog" +BLOG_DESCRIPTION="Latest posts from Andrew's blog" +BLOG_URL="https://blog.laack.co" +AUTHOR_EMAIL="andrew@laack.co" + rm posts/site/*.html INDEX_FILE="posts/site/index.html" @@ -7,13 +12,31 @@ echo "<!DOCTYPE html> <html> <head> <meta charset='UTF-8'> -<title>Andrew's Blog</title> +<title>$BLOG_TITLE</title> <link rel='stylesheet' href='style.css'> +<link rel='alternate' type='application/rss+xml' title='RSS Feed' href='feed.xml'> </head> <body> <h1>Blog Posts</h1> +<p><a href='feed.xml'>RSS Feed</a></p> <ol>" > "$INDEX_FILE" +RSS_FILE="posts/site/feed.xml" +echo "<?xml version='1.0' encoding='UTF-8'?> +<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'> +<channel> +<title>$BLOG_TITLE</title> +<link>$BLOG_URL</link> +<description>$BLOG_DESCRIPTION</description> +<language>en-us</language> +<managingEditor>$AUTHOR_EMAIL</managingEditor> +<webMaster>$AUTHOR_EMAIL</webMaster> +<lastBuildDate>$(date -R)</lastBuildDate> +<atom:link href='$BLOG_URL/feed.xml' rel='self' type='application/rss+xml'/>" > "$RSS_FILE" + +declare -A posts_with_dates +declare -a post_files + for FILE in posts/entries/*.md; do [ -e "$FILE" ] || continue BASENAME="$(basename "$FILE" .md)" @@ -23,9 +46,46 @@ for FILE in posts/entries/*.md; do DATE_LINE=$(grep -E '^## Date: ' "$FILE") DATE=${DATE_LINE#'## Date: '} + posts_with_dates["$FILE"]="$DATE" + post_files+=("$FILE") +done + +for ((i=${#post_files[@]}-1; i>=0; i--)); do + FILE="${post_files[i]}" + BASENAME="$(basename "$FILE" .md)" + DATE="${posts_with_dates[$FILE]}" + echo "<li><a href='$BASENAME.html'>$BASENAME</a> - <em>$DATE</em></li>" >> "$INDEX_FILE" + + TITLE=$(grep -m1 '^# ' "$FILE" | sed 's/^# //') + [ -z "$TITLE" ] && TITLE="$BASENAME" + + DESCRIPTION=$(grep -v '^#' "$FILE" | grep -v '^## Date:' | grep -E '^[A-Za-z]' | head -1) + [ -z "$DESCRIPTION" ] && DESCRIPTION="Blog post: $TITLE" + + if [[ "$DATE" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then + RSS_DATE=$(date -d "$DATE" -R 2>/dev/null || echo "$DATE") + else + RSS_DATE="$DATE" + fi + + echo "<item> +<title><![CDATA[$TITLE]]></title> +<link>$BLOG_URL/$BASENAME.html</link> +<description><![CDATA[$DESCRIPTION]]></description> +<pubDate>$RSS_DATE</pubDate> +<guid>$BLOG_URL/$BASENAME.html</guid> +</item>" >> "$RSS_FILE" done echo "</ol> </body> </html>" >> "$INDEX_FILE" + +echo "</channel> +</rss>" >> "$RSS_FILE" + +echo "Blog generated successfully!" +echo "- HTML index: $INDEX_FILE" +echo "- RSS feed: $RSS_FILE" +