blog/make.sh

90 lines
2.5 KiB
Bash
Raw Normal View History

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-28 00:23:50 +00:00
# attempt compilation
if [ ! -e "linkpost" ]
then
go build -o linkpost main.go
fi
lp="$(pwd)/linkpost"
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-30 23:44:10 +00:00
# Remove old gopher and gemini posts
2022-05-23 14:34:25 +00:00
rm -f ${gopherPath}/*
2022-05-30 23:44:10 +00:00
rm -f ${geminiPath}/*
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-28 00:23:50 +00:00
cd $postDir > /dev/null
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
2022-05-30 23:36:12 +00:00
echo "<div class=\"title\">" >> $htmlIndex
2023-04-13 05:46:04 +00:00
echo "<h2>${title}<a name=\"${slug}\"></a></h2>" >> $htmlIndex
echo "<a class=\"pubdate\" href=\"https://tilde.town/~vilmibm/blog#${slug}\">${pubdate}</a>" >> $htmlIndex
2022-05-30 23:36:12 +00:00
echo "</div>" >> $htmlIndex
2022-05-21 05:09:40 +00:00
echo "<div class=\"post\">" >> $htmlIndex
2022-05-28 00:23:50 +00:00
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" | $lp --mode "html" | 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-28 00:23:50 +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-28 00:23:50 +00:00
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" | $lp --mode "gopher" >> $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-28 00:23:50 +00:00
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" | $lp --mode "gemini" >> $geminiPostPath
2022-05-21 05:09:40 +00:00
fi
done
2022-05-21 05:14:52 +00:00
echo "</body></html>" >> $htmlIndex