blog/make.sh

79 lines
2.2 KiB
Bash
Raw Normal View History

2022-05-20 05:43:15 +00:00
#!/bin/bash
set -e
2022-05-21 05:09:40 +00:00
# global
2022-05-20 05:43:15 +00:00
pd=/usr/bin/pandoc
g=/bin/grep
2022-05-21 05:09:40 +00:00
tr=/usr/bin/tr
sed=/bin/sed
2022-05-21 05:19:40 +00:00
sort=/usr/bin/sort
2022-05-20 07:10:18 +00:00
postDir=/home/vilmibm/blog/posts
2022-05-21 05:09:40 +00:00
htmlDir=/home/vilmibm/public_html/blog
htmlIndexTmpl=/home/vilmibm/blog/index.tmpl.html
htmlIndex=/home/vilmibm/public_html/blog/index.html
2022-05-20 05:43:15 +00:00
2022-05-21 05:09:40 +00:00
gopherPath=/home/vilmibm/public_gopher/blog
2022-05-21 05:14:52 +00:00
gopherIndex="${gopherPath}/gophermap"
2022-05-21 05:09:40 +00:00
geminiPath=/home/vilmibm/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
rm ${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-21 05:19:40 +00:00
for p in $(ls *.md | $sort -r)
2022-05-21 05:09:40 +00:00
do
pubdate=$($g "pubdate:" $p | $sed 's/pubdate: //')
title=$($g "title:" $p | $sed 's/title: //')
slug=$($g "slug:" $p | $sed 's/slug: //' | $tr -d \[:blank:\])
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
$g -v "pubdate:" $p | $g -v "title:" | $g -v "slug:" |$pd -fmarkdown -thtml >> $htmlIndex
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
$g -v "pubdate:" $p | $g -v "title:" | $g -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
$g -v "pubdate:" $p | $g -v "title:" | $g -v "slug:" >> $geminiPostPath
fi
done
2022-05-21 05:14:52 +00:00
echo "</body></html>" >> $htmlIndex