From 285bbff7d8e4df3505a1e5d8af271c249ae9eb81 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Sun, 7 Feb 2021 13:15:50 -0500 Subject: [PATCH] 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 :) --- .gitignore | 3 +++ Makefile | 7 +++++-- blog.7 | 6 +++--- genatom.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100755 genatom.sh diff --git a/.gitignore b/.gitignore index 8178697..5a90245 100644 --- 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 index c604615..10c91dd 100644 --- 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 index 79e31e2..677b06d 100644 --- 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 new file mode 100755 index 0000000..90ec272 --- /dev/null +++ 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 <
+ + Alex Karle's blog(7) + + https://alexkarle.com/atom.xml + + + Alex Karle + +HEADER + +set $DATES +printf " %s\n" "${1}T00:00Z" +for p in $POSTS; do + d="$1" + shift + cat < + $p + + https://alexkarle.com/$p.html + ${d}T00:00Z + ${d}T00:00Z + +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' + printf " \n \n" +done +printf "\n" -- libgit2 1.1.1