genatom.sh (1541B) [raw]
1 #!/bin/sh 2 # genatom.sh -- generate atom.xml 3 set -e 4 5 REPO=$(dirname "$(dirname "$0")") 6 7 POSTS=$(grep '^- ../..' "$REPO/www/blog/index.txt" | sed 's#.*/blog/\([^)]*\).*#\1#') 8 9 ARCH="$(uname)" 10 parsedate() { 11 case "$ARCH" in 12 Linux) date +%F --date="$1" ;; 13 *) date -juf"%b %d, %Y" +%F "$1" ;; # assume *BSD 14 esac 15 } 16 17 cat <<HEADER 18 <?xml version="1.0" encoding="utf-8"?> 19 <feed xmlns="http://www.w3.org/2005/Atom"> 20 <title>Alex Karle's blog</title> 21 <link rel="alternate" type="text/html" href="https://alexkarle.com/blog/index.html"/> 22 <id>https://alexkarle.com/atom.xml</id> 23 <link rel="self" type="application/atom+xml" href="https://alexkarle.com/atom.xml"/> 24 <author> 25 <name>Alex Karle</name> 26 </author> 27 HEADER 28 29 for post in $POSTS; do 30 p=$(basename $post .html) 31 src="$REPO/www/blog/$p.txt" 32 [ "$p" = "index" ] && continue 33 34 d=$(parsedate "$(grep '^_Published' "$src" | sed 's/_Published: \([^_]*\)_/\1/')") 35 if [ -z "$printed_update" ]; then 36 printed_update=1 37 printf " %s\n" "<updated>${d}T00:00:00Z</updated>" 38 fi 39 40 title=$(sed -e 's/^# //' -e '1q' "$src") 41 cat <<ENTRY 42 <entry> 43 <title>$title</title> 44 <link rel="alternate" type="text/html" href="https://alexkarle.com/blog/$p.html"/> 45 <id>https://alexkarle.com/blog/$p.html</id> 46 <updated>${d}T00:00:00Z</updated> 47 <published>${d}T00:00:00Z</published> 48 <content type="html"> 49 <![CDATA[ 50 ENTRY 51 nihdoc < "$src" 52 cat <<EOENTRY 53 ]]> 54 </content> 55 </entry> 56 EOENTRY 57 done 58 printf "</feed>\n"