Pezholio

Lost the Source to My Octopress Blog (Ooops)

| Comments

As I use Octopress to publish my blog, there’s no database and no admin panel for my blog. It’s all generated on my local machine, and pushed to Github pages.

On one hand, this is great, hosting is free (on Github), and the site is hella lightweight (just flat HTML pages). I also write my posts in Markdown (which makes writing so much more enjoyable than squinting into a WYSIWIG editor on a webpage), save them on my local machine and then run a couple of commands in my terminal to pubish my new blog post.

The way it’s supposed to work is you should have two branches in GitHub, one for the posts that Octopress generates, and one for the actual source of your blog, so if you forget to push your source to Github (like me), and get a new computer (like me), and don’t BACK EVERYTHING UP (like me), things sort of fall apart at the seams.

I posted a question to StackOverflow about this and, after a day, I got no response, so, with a new blog post I was eager to publish, I decided to get to hacking.

First, I pulled down a new copy of the Octopress source and changed the settings to (more or less) represent what I had before. I also have a modified vesion of the oct2 theme, so I pulled that down and made the modifications I’d done on my old blog.

Next came the hard bit, getting my posts back into the source. I came across this code to import a Blogger export into Octopress, so decided to use this as a basis. I then pulled down my Github pages repo, and made some tweaks to the Blogger code I grabbed to scrape the title, content, published date, and categories out of the published HTML. I didn’t need to worry about comments, as these are hosted on Disqus (because flat HTML remember?)

I then saved my script in the source directory of the cloned Octopress repo, ran it, and all the pages were generated automagically (in HTML, rather than Markdown, as Octopress supports bog standard HTML in case you’re mad and would rather write blog posts in raw HTML). I then ran rake generate and then rake preview to see my new site in all it’s glory.

To my amazement, it worked, and, after setting up Github Pages, I ran rake deploy, and the site was live!

I also remembered to commit my source this time (documented quite clearly(!) here), so hopefully will never have the same problem again.

If you’re an idiot like me, and have done the same thing, you can see my script here, and please, remember to commit your source next time!

Comments