I’ve migrated from Wordpress to Octopress and used the Jekyll wordpress migrator to move my posts over. Unfortunately, this doesn’t preserve post tags. The output looks like this:
12345678
---layout:posttitle:Devops w/ Perl @ Linode PPW Talk Slideswordpress_id:330wordpress_url:http://michael.thegrebs.com/?p=330date:2011-10-27 14:46:31 -04:00---Earlier this month I gave a talk about...
Having the wordpress post id means extracting the post tags from the db should be quite easy. First we define our desired output:
123456789
---layout:posttitle:Devops w/ Perl @ Linode PPW Talk Slideswordpress_id:330wordpress_url:http://michael.thegrebs.com/?p=330date:2011-10-27 14:46:31 -04:00tags:geek perl slides---Earlier this month I gave a talk about ...
The tags field really can appear anywhere in this YAML fragment but I chose to throw it at the end. With 103 posts to loop over, run a query and insert a new line a short script makes sense. The real win for our script though is using the Tie::File module which presents each file as an array with an element for each line.
From there it’s simply a matter of reverse engineering the Wordpress schema to come up with a query that will return a space delimited list of tags for a given post id.