commit 76ebfc74605aaff4efe421db9d6e813546bfe7cc
parent d55d731007b7adbe18e2742c1f20518bb06165e0
Author: phoebos <ben@bvnf.space>
Date: Fri, 30 Jun 2023 04:06:49 +0100
blog: add feed
Diffstat:
4 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/blog/.gitignore b/blog/.gitignore
@@ -1,2 +1,3 @@
*.txt
index.html
+rss.xml
diff --git a/blog/Makefile b/blog/Makefile
@@ -3,7 +3,7 @@
TXTS = \
001-this-server.txt \
-all: ${TXTS} index.html
+all: ${TXTS} index.html rss.xml
.SUFFIXES: .7 .txt
@@ -13,8 +13,11 @@ all: ${TXTS} index.html
index.html:
./gen-index.sh
+rss.xml:
+ ./gen-feed.sh > rss.xml
+
clean:
- rm -f ${TXTS} index.html
+ rm -f ${TXTS} index.html rss.xml
lint:
mandoc -T lint $(TXTS:.txt=.7)
diff --git a/blog/gen-feed.sh b/blog/gen-feed.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+blogtitle="ben's space"
+urlroot="https://bvnf.space/blog"
+urlblog="https://bvnf.space/blog/"
+
+# HEADER
+cat << EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0">
+<channel>
+<title>$blogtitle</title>
+<link>$urlblog</link>
+<copyright>CC0</copyright>
+<language>en</language>
+<lastBuildDate>$(date "+%a, %e %b %Y %H:%M:%S %z")</lastBuildDate>
+
+EOF
+
+ls -r -- *.txt *.gmi *.html | while read -r f; do
+ unset date title desc link in
+ # hack for same-day posts
+ case "$f" in
+ 006*) time="01" ;;
+ *) time="00" ;;
+ esac
+ case "$f" in
+ index.html) continue ;;
+ *.txt)
+ link="$urlroot/$f"
+ in="${f%.txt}.7"
+ date="$(grep '^[.]Dd' "$in" | cut -c 5-)"
+ title="$(grep '^[.]Nm' "$in" | cut -c 5-)"
+ desc=" - $(grep '^[.]Nd' "$in" | cut -c 5-)"
+ ;;
+ *.gmi)
+ link="gemini://gemini.bvnf.space/blog/${f#[0-9][0-9][0-9]-}"
+ title="$(sed 1q "$f")"
+ date="$(sed 1d "$f")"
+ ;;
+ *.html)
+ link="$urlroot/$f"
+ title="$(sed -n 's/.*<title>\(.*\)<\/title>.*/\1/p' "$f")"
+ date="$(date -j +"%B %d, %Y" "$(sed -n 's/^.*written \([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\).*$/\1\2\30000/p' "$f")")"
+ ;;
+ *) continue ;;
+ esac
+
+
+ cat <<EOF
+<item>
+ <title>$title</title>
+ <link>$link</link>
+ <pubDate>$(date -ju "$date" "+%a, %d %b %Y 00:00:${time:-00} %z")</pubDate>
+</item>
+
+EOF
+
+done
+
+# FOOTER
+cat << EOF
+</channel>
+</rss>
+EOF
diff --git a/blog/gen-index.sh b/blog/gen-index.sh
@@ -14,6 +14,7 @@ cat << EOF
<title>ben's blog</title>
<link rel="stylesheet" href="../style.css" type="text/css" />
<link rel="icon" href="data:image/gif;base64,R0lGODlhEAAQAPH/AAAAAP//AAD/AP8AACH/C0NSTkcAAAAAMS4wSAAAAAIwPwAAAAJATwAAAAJQXwAAAAJgbwAAAAJwfwAAAAKAjwAAAAKQnwAAAAKgrwAAAAKwvwAAAALAzwAAAALQ3wAAAALg7wAh+QQF//8EACwAAAAAEAAQAAACOJQFqTp9j5p00IApq8X0rTtBSQCQYIeUZGBmh7qyp8fGpGvV8PyqPt9bJUKiBUYT4SBPRMuH0SgAADs="/>
+ <link rel="alternate" type="application/rss+xml" href="/blog/rss.xml"/>
</head>
<body>
<header><nav>