summaryrefslogtreecommitdiff
path: root/atom.xml.sh
blob: ce74d9451d39d482ff7fad0a6ed20840a1943d99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
now () {
	date --rfc-3339=seconds | sed 's/ /T/'
}


meta () {
	perl -nle '/<meta name="'"$1"'" content="(.*)">/ && print $1' "$2"
}


dates () {
	local published=$(meta "published-on" "$1")
	if [ -z "$published" ]; then
		published=$(git rev-list --no-commit-header --pretty=%aI HEAD -- "$1" | tail -n1)
	fi
	local modified=$(git rev-list --after="2023-12-27 00:45+01:00" -1 --no-commit-header --pretty=%aI HEAD -- "$1")
	[ -z "$modified" ] && modified=$(meta "last-modified-on" "$1")
	[ -z "$modified" ] && modified=$published
	echo "<updated>$modified</updated>"
	echo "<published>$published</published>"
}


cat <<HEADER
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>~aki</title>
<id>https://ignore.pl/</id>
<updated>$(now)</updated>
<link rel="self" href="https://ignore.pl/atom.xml"/>
<icon>https://ignore.pl/favicon.png</icon>
<author>
<name>aki</name>
<email>please@ignore.pl</email>
</author>
HEADER
for article in [^_]*.html; do
	if [ "$article" != "index.html" ]; then
		cat <<-ENTRY
		<entry>
		$(grep "<title>" $article)
		<id>https://ignore.pl/$article</id>
		<link href="https://ignore.pl/$article"/>
		$(dates $article)
		</entry>
ENTRY
	fi
done
echo "</feed>"