121 lines
4.0 KiB
Bash
Executable File
121 lines
4.0 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
|
|
htmlIndex=$HOME/public_html/blog/index.html
|
|
|
|
gopherPath=$HOME/public_gopher/blog
|
|
gopherIndex="${gopherPath}/gophermap"
|
|
|
|
geminiPath=$HOME/public_gemini/blog
|
|
geminiIndex="${geminiPath}/index.gmi"
|
|
|
|
rssIndexTmpl=$srcDir/feed.tmpl.xml
|
|
rssIndex=$HOME/public_html/blog/feed.xml
|
|
|
|
# attempt compilation
|
|
if [ ! -e "linkpost" ]
|
|
then
|
|
go build -o linkpost main.go
|
|
fi
|
|
|
|
lp="$(pwd)/linkpost"
|
|
|
|
# backup HTML index
|
|
if [ -e "${htmlIndex}" ]
|
|
then
|
|
cp $htmlIndex "${htmlIndex}.bak"
|
|
fi
|
|
|
|
# backup RSS feed
|
|
if [ -e "${rssIndex}" ]
|
|
then
|
|
cp $rssIndex "${rssIndex}.bak"
|
|
fi
|
|
|
|
cp $htmlIndexTmpl $htmlIndex
|
|
cp $rssIndexTmpl $rssIndex
|
|
|
|
# Remove old gopher and gemini posts
|
|
rm -f ${gopherPath}/*
|
|
rm -f ${geminiPath}/*
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
cd $postDir > /dev/null
|
|
|
|
metadataKeys="pubdate:|title:|slug:|summary:"
|
|
|
|
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:\])
|
|
summary=$(grep "summary:" $p | sed 's/summary: //' | tr -d \[:blank:\])
|
|
httpLink="https://tilde.town/~vilmibm/blog#${slug}"
|
|
if [ -z "$pubdate" ] || [ -z "$title" ] || [ -z "$slug" ] || [ -z "$summary" ]
|
|
then
|
|
echo "warning: missing at least one of: pubdate, slug, title, summary in ${p}"
|
|
else
|
|
# HTML
|
|
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
|
|
|
|
|
|
# Gopher
|
|
echo "0${title} ${slug}.txt" >> $gopherIndex
|
|
gopherPostPath="${gopherPath}/${slug}.txt"
|
|
echo "# ${title}" > $gopherPostPath
|
|
echo >> $gopherPostPath
|
|
echo "_published ${pubdate}_" >> $gopherPostPath
|
|
grep -Ev "$metadataKeys" $p | $lp --mode "gopher" >> $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 -Ev "$metadataKeys" $p | $lp --mode "gemini" >> $geminiPostPath
|
|
|
|
# RSS
|
|
echo " <item>" >> $rssIndex
|
|
echo " <title>${title}</title>" >> $rssIndex
|
|
echo " <link>${httpLink}</link>" >> $rssIndex
|
|
echo " <guid>${httpLink}</guid>" >> $rssIndex
|
|
echo " <pubDate>${rfc822pubDate}</pubDate>" >> $rssIndex
|
|
echo " <description>${summary}</description>" >> $rssIndex
|
|
echo " </item>" >> $rssIndex
|
|
fi
|
|
done
|
|
|
|
# Finalize HTML
|
|
echo "</body></html>" >> $htmlIndex
|
|
|
|
# Finalize RSS
|
|
echo " </channel>" >> $rssIndex
|
|
echo "</rss>" >> $rssIndex
|