blog/make.sh

122 lines
4.0 KiB
Bash
Raw Normal View History

2022-05-20 05:43:15 +00:00
#!/bin/bash
set -e
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
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
2024-05-19 22:07:40 +00:00
rssIndexTmpl=$srcDir/feed.tmpl.xml
rssIndex=$HOME/public_html/blog/feed.xml
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
2024-05-19 22:07:40 +00:00
# backup RSS feed
if [ -e "${rssIndex}" ]
then
cp $rssIndex "${rssIndex}.bak"
fi
2022-05-21 05:09:40 +00:00
cp $htmlIndexTmpl $htmlIndex
2024-05-19 22:07:40 +00:00
cp $rssIndexTmpl $rssIndex
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
2024-05-19 22:07:40 +00:00
# Initialize rss
rfc822pubDate="$(date +'%a, %d %b %Y %H:%M:%S %Z')"
printf " <pubDate>%s</pubDate>\n" "${rfc822pubDate}" >> $rssIndex
printf " <lastBuildDate>%s</lastBuildDate>\n" "${rfc822pubDate}" >> $rssIndex
2022-05-28 00:23:50 +00:00
cd $postDir > /dev/null
2024-05-19 22:07:40 +00:00
metadataKeys="pubdate:|title:|slug:|summary:"
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:\])
2024-05-19 22:16:07 +00:00
summary=$(grep "summary:" $p | sed 's/summary: //')
2024-05-19 22:07:40 +00:00
httpLink="https://tilde.town/~vilmibm/blog#${slug}"
if [ -z "$pubdate" ] || [ -z "$title" ] || [ -z "$slug" ] || [ -z "$summary" ]
2022-05-21 05:09:40 +00:00
then
2024-05-19 22:07:40 +00:00
echo "warning: missing at least one of: pubdate, slug, title, summary in ${p}"
2022-05-21 05:09:40 +00:00
else
# HTML
2024-05-19 22:07:40 +00:00
echo "<div class=\"title\">" >> $htmlIndex
echo " <h2>${title}<a name=\"${slug}\"></a></h2>" >> $htmlIndex
echo " <a class=\"pubdate\" href=\"${httpLink}\">${pubdate}</a>" >> $htmlIndex
echo "</div>" >> $htmlIndex
echo "<div class=\"post\">" >> $htmlIndex
grep -Ev "$metadataKeys" $p | $lp --mode "html" | pandoc -fmarkdown -thtml >> $htmlIndex
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"
2024-05-19 22:07:40 +00:00
echo "# ${title}" > $gopherPostPath
echo >> $gopherPostPath
echo "_published ${pubdate}_" >> $gopherPostPath
grep -Ev "$metadataKeys" $p | $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"
2024-05-19 22:07:40 +00:00
echo "# ${title}" > $geminiPostPath
echo >> $geminiPostPath
echo "_published ${pubdate}_" >> $geminiPostPath
grep -Ev "$metadataKeys" $p | $lp --mode "gemini" >> $geminiPostPath
# RSS
2024-05-19 22:16:07 +00:00
rfc822=$(date -d"$pubdate" +'%a, %d %b %Y %H:%M:%S %Z')
2024-05-19 22:07:40 +00:00
echo " <item>" >> $rssIndex
echo " <title>${title}</title>" >> $rssIndex
echo " <link>${httpLink}</link>" >> $rssIndex
echo " <guid>${httpLink}</guid>" >> $rssIndex
2024-05-19 22:16:07 +00:00
echo " <pubDate>${rfc822}</pubDate>" >> $rssIndex
2024-05-19 22:07:40 +00:00
echo " <description>${summary}</description>" >> $rssIndex
echo " </item>" >> $rssIndex
2022-05-21 05:09:40 +00:00
fi
done
2022-05-21 05:14:52 +00:00
2024-05-19 22:07:40 +00:00
# Finalize HTML
2022-05-21 05:14:52 +00:00
echo "</body></html>" >> $htmlIndex
2024-05-19 22:07:40 +00:00
# Finalize RSS
echo " </channel>" >> $rssIndex
echo "</rss>" >> $rssIndex