I did a half-hearted port from Markdown to Orgmode for the underlying text of this site. And I also did a half-hearted port to using Hugo page bundles (in anticipating of getting webmentions working).
But the time has come for me to fix things up properly.
First of all, I need to covert my text files from being formated using markdown to be using Orgmode. Enter pandoc
.
But that mucks up my frontmatter (that's really important to Hugo). So, enter sed
.
The two scripts that do the heavy lifting, are a shell script ConvertToOrg.sh
for INFILE in $(grep -L "^#+date" */*.org)
do
echo "Covertingt from Markdown: " $INFILE
export OUTFILE=$INFILE.txt
pandoc -f markdown -t org -o $OUTFILE $INFILE
echo "Fixing frontmatter in: " $OUTFILE
sed -f fixFrontmatter.sed $OUTFILE > $INFILE
done
and the sed
script, fixFrontmatter.sed
, looks like this:
/./{H;$!d} ;
x;
/+++/,2{
s/^[[:space:]]//;
s/[[:space:]]/ /g;
s/\+\+\+// ;
s/ *title = "\([^"]*\)"/#+title: \1\n/ ;
s/ *date = "\([^"]*\)"/#+date: \1\n#+lastmod: \1\n/ ;
s/ *categories[^"]*"\([^"]*\)"]/#+categories[]: \1\n#+tags[]: \n/ ;
s/ *draft = "\([^"]*\)"/#+draft: \1\n/ ;
s/ +++ /\n/ ;
}
/:PROPERTIES:/d
/:END:/d
/:CUSTOM_ID:/d
Getting the multi-line replaces working in sed
took some time, but I've come to kinda of like sed now.
All in all, it's all a bit of a kludge and it's not 100%. I'm now going through all my old posts to check and touch-up the converted files.
Update 2021-12-30 Thu
This update to my site has also see me strip out the pages that detail my publications, my teaching (courses), and the details of my individual runs.
That'll cause a little link rot. But I doubt many/any folk will notices.