You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

output() {
echo "$1" >> index.html
output_rss() {
echo "$1" >> rss.xml
add_header() {
output '<h1>Blog index</h1><table id="linklist">'
output_rss '<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="" xml:lang="en">
<title>kagerus blog</title>'
output_rss " <link href=\"$blog_domain\" rel=\"self\" type=\"application/atom+xml\"/>
<description>kagerus blog</description>"
add_footer() {
html_entry "legacy" "before 2020" "Older posts"
output '</table>'
output_rss '</feed>'
html_entry() {
output '<tr>'
output "<td class=\"first\"><a href=\"$path\">$title</a></td>"
output "<td class=\"second\">$time</td></tr>"
rss_entry() {
# The content is the output minus the first line
# (which would otherwise be a redundant title in most rss readers)
# and with escaped html.
# The sed expression is stolen from
output_rss " <entry>
<link href=\"$blog_domain$2\" type=\"text/html\" title=\"$1\"/>
<content type=\"html\" xml:base=\"$blog_domain$2\">
$(tail -n+2 "$2" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g')
create_entry() {
outpath="content/$(basename "$path" .md).html"
# convert new markdown posts to html
pandoc "$path" -t html -f markdown -o "$outpath"
# then add it to the index
title="$(rg 'h1' "$outpath" | head -n1 | rg -o '(?<=>).*(?=<)' --pcre2)"
created=$(git log --follow --format=%as "$path" | tail -1)
html_entry "$outpath" "created on $created" "$title"
rss_entry "$title" "$outpath"
has_updates() {
git fetch &> /dev/null
diff="$(git diff master origin/master)"
if [ "$diff" ]; then
return 0
return 1
cd /home/nginx/html/blog
if has_updates; then
git pull &> /dev/null
rm -f index.html
rm -f rss.xml
ls -ltu src/*.md | tail -n+1 | while read f; do create_entry $f; done
# Human-readable output for the cron notification
echo 'Updated blog to:'
git log -1