writing an atom feed generator in shellscript, or WDIIODTTHW: the sequel

to make it easier for the 1 people who read this blog

(please get in touch if you're reading this i need to increment the counter)

why

i needed to feel something

also its fun to read thru and implement standards!

screw being normal :P

rss?

i could do that too tbh, should be quite simple since all the helper functions are already in place

EDIT 04/07/24: finally got around to adding an rss feed hope it doesn't break too bad! ok im checking against the w3c validator and theres a concerning amount of yellow highlight itll be fine :P it wasnt but i checked some other rss feeds from blogs i follow and they have funny yellow too oh i gotta use cdata yippee Congratulations! This is a valid RSS feed.

ok but why shellscript

everything i touch turns to shell

here's the code:

sortbytc() {
	[ -e "$1" ] || return
	for f in "$@"; do
		local timestamp="$(git log --diff-filter=A --follow --format='%at' -1 -- "$f")"
		if [ -z "$timestamp" ]; then
			git >/dev/null 2>&1 ls-files --error-unmatch -- "$f" || continue
			timestamp="$(stat -c '%Z' "$f")"
		fi
		echo "$f $timestamp"
	done | sort -r -k2 | cut -d ' ' -f 1
}

genatom() {
	cat <<-.
	<?xml version="1.0" encoding="utf-8"?>
	<feed xmlns="http://www.w3.org/2005/Atom">
		<title>notchoc blogs posts</title>
		<subtitle>in which notchoc uses software and complains about it</subtitle>
	.

	for f in $(sortbytc *.md); do
		cat <<-.
		<entry>
			<title>$(sed '1s/^##* //;q' "$f")</title>
			<link href="${f%.md}.html" ref="alternate" type="text/html" />
			<published>$(git log --diff-filter=A --follow --date=format:'%Y-%m-%dT%H:%M:%SZ' --format='%ad' -1 -- "$f")</published>
			<updated>$(git log --follow --date=format:'%Y-%m-%dT%H:%M:%SZ' --format='%ad' -1 -- "$f")</updated>
			<summary>$(summarize "$f")</summary>
			<content>
				$(sed '1{/^##*/d}' "$f" | contents)
			</content>
		</entry>
		.
	done

	cat <<-.
	</feed>
	.
}

its not very robust i needed to filter the files through git i had too many unfinished blogposts sitting around and it was generating ghost redirects look, new custom ramble spoiler thingy! it's just regex replacing (|| and ||) under the hood please don't look at how i got those to render but hey it gets the job done

btw all the .md files and scripts that i use in this site are up on codeberg (and accessible thru here as well if u have the right path)

anyways you can get the feed here


made with <3 and /.gen.sh