site

A custom static site generator written in C.
git clone https://unitehenry.com/git/site.git
Log | Files | Refs | README

commit 9aa52fcbbcdaf3808b4012e0099a5672ff0f9a55
parent 12c090d91dfc44f73592219a1b1dd73cae81b373
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sat, 28 Nov 2026 20:19:49 +0000

refactor(rss): read blog entries from content/index.md

Diffstat:
Mscripts/rss | 111++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 104 insertions(+), 7 deletions(-)

diff --git a/scripts/rss b/scripts/rss @@ -3,7 +3,12 @@ RSS_TITLE="unitehenry" RSS_DESCRIPTION="cracked software engineer" PUBLIC_URL="https://unitehenry.com" -BLOG_INDEX="build/blog/index.html" +BLOG_INDEX="content/index.md" + +if [ ! -f "$BLOG_INDEX" ]; then + echo "error: $BLOG_INDEX not found" >&2 + exit 1 +fi echo '<?xml version="1.0" encoding="UTF-8"?>' echo '<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">' @@ -13,12 +18,104 @@ echo "<link>$PUBLIC_URL/blog</link>" echo "<description>$RSS_DESCRIPTION</description>" echo '<language>en-us</language>' -cat $BLOG_INDEX | htmlq -a id h2 | while read -r line; do - TITLE=$(cat $BLOG_INDEX | htmlq -t "#$line") - DATE=$(cat $BLOG_INDEX | htmlq -t "#$line + p") - DESCRIPTION=$(cat $BLOG_INDEX | htmlq -t "#$line + p + p") - SLUG=$(cat $BLOG_INDEX | htmlq -a href "#$line + p + p + p a") - CONTENT=$(cat "build/$SLUG.html" | htmlq main | sed 's/<main>//;s/<\/main>//') +# Read the blog entries from the details blocks in the homepage's blog section. +awk ' + function trim(s) { + gsub(/^[[:space:]]+|[[:space:]]+$/, "", s) + return s + } + + function add_paragraph(text) { + text = trim(text) + + if (date == "") { + date = text + } else if (description == "") { + description = text + } + } + + /^## blog[[:space:]]*$/ { + in_blog = 1 + next + } + + in_blog && /^## / { + exit + } + + in_blog && /<details>/ { + in_item = 1 + title = "" + date = "" + description = "" + slug = "" + summary = "" + paragraph = "" + in_summary = 0 + in_paragraph = 0 + next + } + + in_blog && in_item && /<\/details>/ { + if (slug != "") { + printf "%s\t%s\t%s\t%s\n", title, date, description, slug + } + + in_item = 0 + next + } + + in_blog && in_item { + line = trim($0) + + if (line ~ /<summary>/) { + in_summary = 1 + sub(/^.*<summary>/, "", line) + } + + if (in_summary) { + if (line ~ /<\/summary>/) { + sub(/<\/summary>.*$/, "", line) + summary = trim(summary " " line) + + index_separator = index(summary, " • ") + title = index_separator ? trim(substr(summary, 1, index_separator - 1)) : summary + + if (match(summary, /\(\/blog\/[^)]+\)/)) { + slug = substr(summary, RSTART + 1, RLENGTH - 2) + } + + in_summary = 0 + } else { + summary = summary " " line + } + + next + } + + if (line ~ /<p>/) { + in_paragraph = 1 + sub(/^.*<p>/, "", line) + } + + if (in_paragraph) { + if (line ~ /<\/p>/) { + sub(/<\/p>.*$/, "", line) + add_paragraph(paragraph " " line) + paragraph = "" + in_paragraph = 0 + } else { + paragraph = paragraph " " line + } + + next + } + } +' "$BLOG_INDEX" | while IFS=$'\t' read -r TITLE DATE DESCRIPTION SLUG; do + [ -n "$SLUG" ] || continue + + CONTENT=$(cat "build$SLUG.html" | htmlq main | sed 's/<main>//;s/<\/main>//') CLEAN_DATE=$(echo "$DATE" | sed 's/th//;s/st//;s/nd//;s/rd//') PUBDATE=$(date -R -d "$CLEAN_DATE" 2>/dev/null || echo "$DATE")