Mike Stone

Mostly The Lonely Howls Of Mike Baying His Ideological Purity At The Moon

Migrating Posts To Jekyll

18 Jan 2021

I wrote in my last post about moving from write.as to Jekyll. Kev wrote an extensive guide on how to create a Jekyll site using Simple.css, the hardest part about this process (other than customizing the new blog to my personal tastes, which I’m still working on) was moving my old content over to the new blog. Here’s how I did it.

The first thing to do is somehow get the content from write.as. Fortunately, they’ve been nice enough to include an export option in the menu.

After that, you’re given a few different choices.

This is where things kind of went off the rails for me at first. I downloaded them all because I didn’t know which would be the easiest to work with.

It turns out that csv is the worst option. It gives you the contents of the your posts, so if that’s all you’re interested in, you’re probably going to be fine. What it didn’t give me that I wanted was a way to preserve the date that the post was made.

I’ve been dragging around many of my old posts, and my oldest dates back to 2002. Honestly, that wasn’t even originally a blog post, it was a stand alone page on my website. I’m getting off into the weeds here though.

I didn’t want all my posts to have a new published date in 2021, so I started looking at other options. I next chose the prettified json. There was no real difference between it and the other json version, and this one was prettier.

I spent some time digging through the json, and even wrote some really basic Python to try to export what I needed from there, but I just don’t have the skills with Python to make that work. After spending an hour or more beating my head against the wall trying to make that work, I took a closer look at the text option.

I initially dismissed the text option because it basically just exported the markdown files as text in a big zip document. The markdown as pretty much exactly as I’d entered into the page, with no further information.

This is where muscle memory saved me.

I just randomly typed in “ls -alrt” in my terminal, which displays all the files in chronological order. I noticed that the text files were dated as being last modified on the date they were created on the site.

The files had the published date!

From there, things were really pretty simple. I had almost 180 posts that I wanted to move over, so I didn’t wan to do this manually, but a script was a pretty simple option since all the information I needed was there and available.


for x in *.txt
  FILE_NAME=`echo ${x}|cut -d_ -f1`
  FILE_DATE=`stat ${x}|grep Modify|cut -d" " -f2`
  FILE_TIME=`stat ${x}|grep Modify|cut -d" " -f 3|cut -d. -f1`
  POST_TITLE=`head -1 ${x}|sed s/"# "//`
  TAIL_VALUE=`cat ${x}|wc -l`

  echo Converting ${x} to ${FILE_NAME_NEW}

  echo --- >> ${FILE_NAME_NEW}
  echo title: ${POST_TITLE} >> ${FILE_NAME_NEW}
  echo  >> ${FILE_NAME_NEW}
  echo description: Mostly The Lonely Howls Of Mike Baying His Ideological Purity At The Moon >> ${FILE_NAME_NEW}
  echo permalink: /${FILE_NAME}/ >> ${FILE_NAME_NEW}
  echo 'excerpt_separator: <!--more-->' >> ${FILE_NAME_NEW}
  echo layout: post >> ${FILE_NAME_NEW}
  echo date: ${FILE_DATE} ${FILE_TIME} >> ${FILE_NAME_NEW}
  echo published: true >> ${FILE_NAME_NEW}
  echo --- >> ${FILE_NAME_NEW}
  echo >> ${FILE_NAME_NEW}
  tail -${TAIL_VALUE} ${x} >> ${FILE_NAME_NEW}


The script above was able to extract the information from the text files and place it where it belonged in the front matter of the new markdown files for Jekyll. From there it was a simple matter of dropping them into the proper directory and publishing the page with all my old content.

Day 4 of the #100DaysToOffload 2021 Series.

Looking for comments? There are no comments. It's not that I don't care what you think, it's just that I don't want to manage a comments section.

If you want to comment, there's a really good chance I at least mentioned this post on Fosstodon, and you can reply to me there. If you don't have a Mastodon account, I'd suggest giving it a try.

If you don't want to join Mastodon, and you still want to comment, feel free to use my contact information.

Also, don't feel obligated, but if you feel like buying me a ☕ cup of coffee ☕ I won't say no.