commit 285bbff7d8e4df3505a1e5d8af271c249ae9eb81 (patch)
parent 470925594386a74c4e77923aec85b13a72d0698a
Author: Alex Karle <alex@alexkarle.com>
Date: Sun, 7 Feb 2021 13:15:50 -0500
make: Add atom feed to the build process!
This was a really fun sunday-morning activity. I learned a bit about the
Atom syndication format, and had some fun scripting up a simple generator
to take blog.7 and output a single atom.xml feed with the full content of
all articles in it!
I recently started using RSS/Atom, and I think it's a great alternative to
link aggregation sites (and social media)--like most things with this site,
I try to model the web I would love to see, so I had to put my money where
my mouth was and add atom to alexkarle.com :)
Diffstat:
4 files changed, 60 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,2 +1,5 @@
# generated html from man pages
*.html
+
+# atom feed is generated by ./genatom.sh
+atom.xml
diff --git a/Makefile b/Makefile
@@ -9,15 +9,18 @@ HTML != echo index.html *.[1-9] | sed 's/\.[1-9]/.html/g'
HIDE = @
.PHONY: build
-build: $(HTML)
+build: $(HTML) atom.xml
.PHONY: clean
clean:
- rm -f $(HTML)
+ rm -f $(HTML) atom.xml
index.html:
ln -sf intro.html $@
+atom.xml:
+ ./genatom.sh > $@
+
.SUFFIXES: .7 .html
.7.html:
@echo "mandoc $<"
diff --git a/blog.7 b/blog.7
@@ -19,13 +19,13 @@ for this site's source (12/30/2020)
- On Writing Without an Audience (10/22/2020)
.It
.Xr self-hosted 7
-- Migrating to a Self-Hosted Site (7/19/2020)
+- Migrating to a Self-Hosted Site (07/19/2020)
.It
.Xr BLM 7
-- Black Lives Matter (7/13/2020)
+- Black Lives Matter (07/13/2020)
.It
.Xr domain-names 7
-- What's in a (domain) name? (3/24/2020)
+- What's in a (domain) name? (03/24/2020)
.It
.Xr a-new-hope 7
- A New Hope (12/19/2019)
diff --git a/genatom.sh b/genatom.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# genatom.sh -- generate atom.xml
+set -e
+
+# All posts are a item (.It) in the list, and linked via .Xr
+POSTS=$(sed '/SEE ALSO/q' blog.7 | grep -A1 '\.It' | grep '\.Xr' | sed 's/^\.Xr \([^ ]*\) 7/\1/')
+# Assume dates are 1-1
+DATES=$(grep -o '[0-9]\{1,2\}/[0-9]\{1,2\}/[0-9]\{4\}' blog.7 \
+ | sed -e 's#\([0-9]\{2\}\)/\([0-9]\{2\}\)/\([0-9]\{4\}\)#\3-\1-\2#')
+
+cat <<HEADER
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title>Alex Karle's blog(7)</title>
+ <link rel="alternate" type="text/html" href="https://alexkarle.com/blog.html"/>
+ <id>https://alexkarle.com/atom.xml</id>
+ <link rel="self" type="application/atom+xml" href="https://alexkarle.com/atom.xml"/>
+ <author>
+ <name>Alex Karle</name>
+ </author>
+HEADER
+
+set $DATES
+printf " %s\n" "<updated>${1}T00:00Z</updated>"
+for p in $POSTS; do
+ d="$1"
+ shift
+ cat <<ENTRY
+ <entry>
+ <title>$p</title>
+ <link rel="alternate" type="text/html" href="https://alexkarle.com/$p.html"/>
+ <id>https://alexkarle.com/$p.html</id>
+ <updated>${d}T00:00Z</updated>
+ <published>${d}T00:00Z</published>
+ <content type="html">
+ENTRY
+ # Print fragment, with XML escaped properly:
+ # https://stackoverflow.com/questions/1091945/what-characters-do-i-need-to-escape-in-xml-documents
+ # Note that & is already escaped in the HTML content by mandoc
+ mandoc -Thtml -O'fragment,man=%N.html;https://man.openbsd.org/%N.%S' $p.7 \
+ | sed \
+ -e 's/^/ /' \
+ -e 's/"/\"/g' \
+ -e "s/'/\\'/g" \
+ -e 's/</\</g' \
+ -e 's/>/\>/g'
+ printf " </content>\n </entry>\n"
+done
+printf "</feed>\n"