migrating wordpress post links to octopress post links

Sat, Jun 8, 2013

So I've migrated the blog to Octopress, got FTP deployment working, and deployed via FTP so what's left I hear you say? Well exitwp doesn't change the internal post links. In the Wordpress post, an internal link to another post, for my blog setup is:


while the link to the same post in the Octopress version of the blog is:


clearly some ruby is required.

What the following code does is loop through every file in the _posts directory looking for Wordpress style links to this particular blog. For each link it finds, It pulls the post id and then looks it up in the Wordpress export XML file to find its title and publication date. The -C 1 flag to grep pulls out the line above and the line below the matching line, so you get:

It then turns the title into a slug, munges the pubDate into an Octopress date and uses the same technique as updating the gists. It does a system call with find to find and replace all occurrences of the Wordpress post link with the Octopress version of the link.

You'll need to adjust the paths and regex to suit your blog but this should sort out all the internal post links.

comments powered by Disqus