78 lines
2.3 KiB
Bash
Executable File
78 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
|
|
mkdir -p "${HOME}/public_gopher/blog" > /dev/null
|
|
mkdir -p "${HOME}/public_gemini/blog" > /dev/null
|
|
mkdir -p "${HOME}/public_html/blog" > /dev/null
|
|
|
|
srcDir=$HOME/blog
|
|
postDir=$srcDir/posts
|
|
|
|
htmlIndexTmpl=$srcDir/index.tmpl.html
|
|
htmlDir=$HOME/public_html/blog
|
|
htmlIndex=$HOME/public_html/blog/index.html
|
|
|
|
gopherPath=$HOME/public_gopher/blog
|
|
gopherIndex="${gopherPath}/gophermap"
|
|
|
|
geminiPath=$HOME/public_gemini/blog
|
|
geminiIndex="${geminiPath}/index.gmi"
|
|
|
|
cd $postDir > /dev/null
|
|
|
|
# backup HTML index
|
|
if [ -e "${htmlIndex}" ]
|
|
then
|
|
cp $htmlIndex "${htmlIndex}.bak"
|
|
fi
|
|
|
|
cp $htmlIndexTmpl $htmlIndex
|
|
|
|
# Remove old gopher posts
|
|
rm -f ${gopherPath}/*
|
|
|
|
# Initialize blog gophermap
|
|
echo "!the phlog of vilmibm as it were" > $gopherIndex
|
|
echo >> $gopherIndex
|
|
|
|
# Initialize blog index for gemini
|
|
echo "the gemblog of vilmibm as it were" > $geminiIndex
|
|
echo >> $geminiIndex
|
|
|
|
for p in $(ls *.md | sort -r)
|
|
do
|
|
pubdate=$(grep "pubdate:" $p | sed 's/pubdate: //')
|
|
title=$(grep "title:" $p | sed 's/title: //')
|
|
slug=$(grep "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
|
|
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" | pandoc -fmarkdown -thtml >> $htmlIndex
|
|
echo "</div>" >> $htmlIndex
|
|
|
|
# Gopher
|
|
echo "0${title} ${slug}.txt" >> $gopherIndex
|
|
gopherPostPath="${gopherPath}/${slug}.txt"
|
|
echo "# ${title}" > $gopherPostPath
|
|
echo >> $gopherPostPath
|
|
echo "_published ${pubdate}_" >> $gopherPostPath
|
|
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" >> $gopherPostPath
|
|
|
|
# Gemini
|
|
echo "=> gemini://tilde.town/~vilmibm/blog/${slug}.gmi ${title}" >> $geminiIndex
|
|
geminiPostPath="${geminiPath}/${slug}.gmi"
|
|
echo "# ${title}" > $geminiPostPath
|
|
echo >> $geminiPostPath
|
|
echo "_published ${pubdate}_" >> $geminiPostPath
|
|
grep -v "pubdate:" $p | grep -v "title:" | grep -v "slug:" >> $geminiPostPath
|
|
fi
|
|
done
|
|
|
|
echo "</body></html>" >> $htmlIndex
|