So I migrated over from github’s pages, which meant I had all of my old markdown posts stored locally. I had asked the micro.blog support folks about migration awhile back and was directed to a nifty little import script which used nodejs. But lo, in the meanwhile, an import button had showed up!
I still needed to insert the date into the frontmatter. My old posts had the date pre-pended to the filename (ie, 2020-01-08-some-title-here.markdown
), so after bashing (har) my head against the wall for awhile, I came up with this, which cuts the leading date fields off the file and jams it into place at line 3. Hooray for Unix.
for i in `ls *.markdown`
do
sed -i "3a\date: `ls $i | cut -d- -f1,2,3`" $i
done
So I went from this at the top of every post:
---
layout: post
title: June Update
---
to this, which was slurped in beautifully:
---
layout: post
title: June Update
date: 2020-07-02
---
Yes, there are other ways to do this. Go nuts. This worked for me. I zipped everything up afterward and had all my old posts moved over lickety-split.