Day Log Atom Feed

When I first added an RSS feed to this wiki, I was deriving it from the git commit log for its pages. I soon found that the commit history didn't correspond well to updates I wanted to push out, which resulted in me just not tracking changes to my wiki pages. After I began keeping a day log, I realized it made a lot more sense to just derive my feed from that. Took me longer than it should have to get around to doing it, but towards the end of July 2025 I finally wrote a shell script to generate a feed consisting of my last nine day log entries, plus the front page message (i.e., the "in progress" day log entry). It sits in the root of my wiki directory tree, alongside the Guile Scheme script that generates the pages themselves and the shell script that uploads it all, and it looks like this:

#!/usr/bin/env bash

DBDIR=day-log.atom.sh.db
ENTRIES=10

entry() {
  updated_tentative=$1
  date=$2
  content=$3
  mkdir -p $DBDIR/$date

  hashfile=$DBDIR/$date/md5sum
  updatedfile=$DBDIR/$date/updated

  hash=$(cat <<EOF | md5sum -
$content
EOF
)

  if [[ ! -e $hashfile ]] || [[ "$hash" != "$(cat $hashfile)" ]]; then
    printf "%s" "$updated_tentative" > $updatedfile
    echo "$hash" > $hashfile
  fi

  cat <<EOF
  <entry>
    <title>$date</title>
    <id>tag:lyk.so,2025:day-log/$date</id>
    <updated>$(cat $updatedfile)</updated>
    <author><name>Lykso</name></author>
    <content type="xhtml" xml:lang="en" xml:base="http://lyk.so/">
      <div xmlns="http://www.w3.org/1999/xhtml">
        $(echo "$content" | tr '\t' '\n')
      </div>
    </content>
  </entry>
EOF
}

cat <<EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 <title type="text">Lykso's Day Log</title>
 <subtitle type="html">
  One entry per day, however trivial. Current day entries may receive updates through the day.
 </subtitle>
 <updated>$updated</updated>
 <id>tag:lyk.so,2025:day-log</id>
 <link rel="alternate" type="text/html" hreflang="en" href="http://lyk.so/day-log.html"/>
 <link rel="self" type="application/atom+xml" href="http://lyk.so/day-log.atom"/>
EOF

cat build/index.html \
| tr '\n' '\t' \
| sed -nE '1h;2,$H;${g;s|.*<h2>([0-9]{4}-[0-9]{2}-[0-9]{2})</h2>(.*)<p><em>Past entries.*|\1\n\2\n|g;p}' \
| sed -nE '1h;2,$H;${g;s|(<a href=")([^:"]+)"|\1http://lyk.so/\2"|g; s|(src=")([^:"]+)"|\1http://lyk.so/\2"|g;p}' \
| {
  read date
  read content
  entry $(date -Isecond --date="$(stat -c%y pages/index.lwl)") "$date" "$content"
}

cat  build/day-log.html \
| tr '\n' '\t' \
| sed -E 's|<h2>([0-9]{4}-[0-9]{2}-[0-9]{2})</h2>|\n\1\n|g; s|<div class="backlinks">.*||' \
| sed -E 's|(<a href=")([^:"]+)"|\1http://lyk.so/\2"|g; s|(src=")([^:"]+)"|\1http://lyk.so/\2"|g' \
| tail -n+2 \
| head -n$(expr "(" "$ENTRIES" - 1 ")" "*" 2) \
| while read date; do
  read content

  entry $(date -Isecond --date="$(stat -c%y pages/day-log.lwl)") "$date" "$content"
done

echo "</feed>"

# Clear out old database entries
ls $DBDIR/ | tail -n+$(expr "$ENTRIES" + 1) | while read e; do
  rm $DBDIR/$e/updated
  rm $DBDIR/$e/md5sum
  rmdir $DBDIR/$e
done

I've hardlinked the script, day-log.atom.sh, into my wiki pages directory so you can download it as it exists currently. If there are discrepancies between the listing above and the file linked in the previous sentence, the file is authoritative. The listing is for convenience, and, until I add file embedding to LWL, may drift.

I really wanted the script to be self-contained, but keeping a record of entry hashes and update timestamps was unavoidable given that I wanted the "updated" tag to be as accurate as possible, so the script keeps a "database directory" of those values and clears out any values belonging to entries that have dropped off the bottom of the feed.

Page Created: 2025-07-22

Last Updated: 2025-07-22

Last Reviewed: 2025-07-22