2022-05-20 05:43:15 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2022-05-21 05:19:40 +00:00
|
|
|
|
2022-05-23 14:34:25 +00:00
|
|
|
mkdir -p "${HOME}/public_gopher/blog" > /dev/null
|
|
|
|
mkdir -p "${HOME}/public_gemini/blog" > /dev/null
|
|
|
|
mkdir -p "${HOME}/public_html/blog" > /dev/null
|
2022-05-20 07:10:18 +00:00
|
|
|
|
2022-05-23 14:34:25 +00:00
|
|
|
srcDir=$HOME/blog
|
|
|
|
postDir=$srcDir/posts
|
2022-05-20 05:43:15 +00:00
|
|
|
|
2022-05-23 14:34:25 +00:00
|
|
|
htmlIndexTmpl=$srcDir/index.tmpl.html
|
|
|
|
htmlDir=$HOME/public_html/blog
|
|
|
|
htmlIndex=$HOME/public_html/blog/index.html
|
|
|
|
|
|
|
|
gopherPath=$HOME/public_gopher/blog
|
2022-05-21 05:14:52 +00:00
|
|
|
gopherIndex="${gopherPath}/gophermap"
|
|
|
|
|
2022-05-23 14:34:25 +00:00
|
|
|
geminiPath=$HOME/public_gemini/blog
|
2022-05-21 05:14:52 +00:00
|
|
|
geminiIndex="${geminiPath}/index.gmi"
|
2022-05-20 05:43:15 +00:00
|
|
|
|
2022-05-21 05:09:40 +00:00
|
|
|
cd $postDir > /dev/null
|
2022-05-20 05:43:15 +00:00
|
|
|
|
2022-05-21 05:09:40 +00:00
|
|
|
# backup HTML index
|
|
|
|
if [ -e "${htmlIndex}" ]
|
|
|
|
then
|
|
|
|
cp $htmlIndex "${htmlIndex}.bak"
|
|
|
|
fi
|
2022-05-20 05:43:15 +00:00
|
|
|
|
2022-05-21 05:09:40 +00:00
|
|
|
cp $htmlIndexTmpl $htmlIndex
|
2022-05-20 05:43:15 +00:00
|
|
|
|
2022-05-21 05:09:40 +00:00
|
|
|
# Remove old gopher posts
|
2022-05-23 14:34:25 +00:00
|
|
|
rm -f ${gopherPath}/*
|
2022-05-20 05:43:15 +00:00
|
|
|
|
2022-05-21 05:09:40 +00:00
|
|
|
# Initialize blog gophermap
|
|
|
|
echo "!the phlog of vilmibm as it were" > $gopherIndex
|
|
|
|
echo >> $gopherIndex
|
2022-05-20 05:43:15 +00:00
|
|
|
|
2022-05-21 05:14:52 +00:00
|
|
|
# Initialize blog index for gemini
|
|
|
|
echo "the gemblog of vilmibm as it were" > $geminiIndex
|
|
|
|
echo >> $geminiIndex
|
|
|
|
|
2022-05-23 14:34:25 +00:00
|
|
|
for p in $(ls *.md | sort -r)
|
2022-05-21 05:09:40 +00:00
|
|
|
do
|
2022-05-23 14:34:25 +00:00
|
|
|
pubdate=$(grep "pubdate:" $p | sed 's/pubdate: //')
|
|
|
|
title=$(grep "title:" $p | sed 's/title: //')
|
|
|
|
slug=$(grep "slug:" $p | sed 's/slug: //' | tr -d \[:blank:\])
|
2022-05-21 05:09:40 +00:00
|
|
|
if [ -z "$pubdate" ] || [ -z "$title" ] || [ -z "$slug" ]
|
|
|
|
then
|
|
|
|
echo "warning: missing at least one of: pubdate, slug, title in ${p}"
|
|
|
|
else
|
|
|
|
# HTML
|
|
|
|
echo "<h2 class=\"title\">${title}</h2>" >> $htmlIndex
|
|
|
|
echo "<a class=\"pubdate\" name=\"${slug}\" href=\"https://tilde.town/~vilmibm/blog#${slug}\">${pubdate}</a>" >> $htmlIndex
|
|
|
|
echo "<div class=\"post\">" >> $htmlIndex
|
2022-05-23 14:34:25 +00:00
|
|
|
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" | pandoc -fmarkdown -thtml >> $htmlIndex
|
2022-05-21 05:09:40 +00:00
|
|
|
echo "</div>" >> $htmlIndex
|
2022-05-20 07:10:18 +00:00
|
|
|
|
2022-05-21 05:09:40 +00:00
|
|
|
# Gopher
|
|
|
|
echo "0${title} ${slug}.txt" >> $gopherIndex
|
|
|
|
gopherPostPath="${gopherPath}/${slug}.txt"
|
|
|
|
echo "# ${title}" > $gopherPostPath
|
|
|
|
echo >> $gopherPostPath
|
|
|
|
echo "_published ${pubdate}_" >> $gopherPostPath
|
2022-05-23 14:34:25 +00:00
|
|
|
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" >> $gopherPostPath
|
2022-05-20 07:10:18 +00:00
|
|
|
|
2022-05-21 05:09:40 +00:00
|
|
|
# Gemini
|
2022-05-21 05:14:52 +00:00
|
|
|
echo "=> gemini://tilde.town/~vilmibm/blog/${slug}.gmi ${title}" >> $geminiIndex
|
2022-05-21 05:09:40 +00:00
|
|
|
geminiPostPath="${geminiPath}/${slug}.gmi"
|
|
|
|
echo "# ${title}" > $geminiPostPath
|
|
|
|
echo >> $geminiPostPath
|
|
|
|
echo "_published ${pubdate}_" >> $geminiPostPath
|
2022-05-23 14:34:25 +00:00
|
|
|
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" >> $geminiPostPath
|
2022-05-21 05:09:40 +00:00
|
|
|
fi
|
|
|
|
done
|
2022-05-21 05:14:52 +00:00
|
|
|
|
|
|
|
echo "</body></html>" >> $htmlIndex
|