61 lines
1.7 KiB
Bash
61 lines
1.7 KiB
Bash
# generate feed.atom for blog
|
|
|
|
blog_uuid=ab54972a-c095-4177-8a36-b77d48d86bec
|
|
|
|
# sort the posts by ctime, which allows us to be independent of filename
|
|
# this allows for more flexibility :D
|
|
# unlike the index.html file, we can't just sort at the end
|
|
# because we have multiple lines of everything. so we have
|
|
# to do a 2-pass
|
|
feed="$_BUILDDIR/blog/feed.atom"
|
|
|
|
for f in *.md; do
|
|
mtime="" ctime=""
|
|
set_md_metadata "$f"
|
|
all_ctimes="$ctime $f$_NL$all_ctimes"
|
|
all_mtimes="${mtime:-"$ctime"}$_NL$all_mtimes"
|
|
done
|
|
|
|
while IFS= read -r _entry; do
|
|
_entry="${_entry#* }"
|
|
{
|
|
ctime="" mtime=""
|
|
_entry="${_entry##*/}"
|
|
set_md_metadata
|
|
|
|
# xml-compatible title
|
|
title="$(__lowdown <<-EOF
|
|
$title
|
|
EOF
|
|
)"
|
|
title="${title#*>}"
|
|
title="${title%<*}"
|
|
|
|
# if mtime null, set it to ctime for the purposes of updated stuff
|
|
: "${mtime:="$ctime"}"
|
|
|
|
entries="$entries"'
|
|
<entry>
|
|
<title>'"$title"'</title>
|
|
<link rel="alternate" href="'"/~yosh/blog/${_entry%.md}.html"'" />
|
|
<id>urn:uuid:'"$uuid"'</id>
|
|
<published>'"$ctime"'</published>
|
|
<updated>'"$mtime"'</updated>
|
|
<content type="html">'"$(__lowdown | escapepipe)"'</content>
|
|
</entry>'
|
|
} < "$_entry"
|
|
done <<-EOF
|
|
$(echo "$all_ctimes" | sort -r | head -n 10)
|
|
EOF
|
|
|
|
header='<?xml version="1.0" encoding="UTF-8" ?>
|
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
|
<link rel="self" type="application/atom+xml" href="https://unix.dog/~yosh/blog/feed.atom" />
|
|
<link rel="alternate" type="text/html" href="https://unix.dog/~yosh/blog" />
|
|
<title>yosh'\''s blog</title>
|
|
<author><name>yosh</name></author>
|
|
<updated>'"$(echo "$all_mtimes" | sort -r | head -n 1)"'</updated>
|
|
<id>urn:uuid:'"$blog_uuid"'</id>'
|
|
|
|
printf '%s\n%s\n</feed>' "$header" "$entries" > "$feed"
|