I’ve migrated one of WordPress Websites to OctoPress. It’s easy to done but OctoPress won’t works well as expected. I spent a week to corrected entire post contents to make it compatible with Markdown format and fix some problems encountered when running new blogging platform. Today, I write this post to share my experiences after migrated from WordPress to OctoPress, hope it can help you if you have the same problem.
Redirect 404 url or combine two or more posts
During the editorial process, I found some “thin” posts which I’m planning to combine all of them to new post or delete then redirect the old url to new one. Like WordPress, I can use a plugin to make it done but unfortunately, my website was hosted on a non Apache based server, so I can’t use mod_rewrite or somethings similar.
OctoPress is blogging framework for Jekyll and one of the great things about Jekyll is its simple plugin system. I’ve found approache-redirects, rack-rewrite, Alias Generator… I choosed Alias Generator because it allows me specify aliases on a per blogpost basis, in the YAML front matter:
---
layout: post
title: "Combined post"
date: 2012-12-12 12:12
comments: true
categories: ["programming", "blogging"]
alias: [/blog/url-on-redirects, /blog/thin-content]
---
When I deploy my site, the Alias Generator will create another static html file with <meta http-equiv='refresh' content='0;url=/combined-post/' />
meta tag to redirect visitor to new url:
<meta http-equiv='refresh' content='0;url=/combined-post/' />
If you want to do more like real mod_rewrite on Apache server, let’s trying rack-rewrite.
Fixing syntax highlighting errors on system with default Python3
Octopress using pygments
as syntax highlighting generator but currently, it’s only working with Python 2. I’m using Arch Linux that’s using Python 3 as default, so when I’m generating or previewing a new posts containing code snippets or embedded gists, I got error:
/home/narga/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/pygments.rb-0.3.4/lib/pygments/popen.rb:354:in `rescue in get_header': Failed to get header. (MentosError)
or
Liquid Exception: Failed to get header. in post-with-code-snippets.markdown
To workaround this, I use virtualenv
to sandbox Python installations. It can redirect python to Python 2 inside a virtualenv
. Let’s see how to make it works:
# pacman -S python2-virtualenv
$ mkdir -p ~/.virtualenvs/my_env
$ virtualenv2 ~/.virtualenvs/my_env
Activate the virtualenv
:
$ source ~/.virtualenvs/my_env/bin/activate
(my_env)[narga ~/Briefcase/octopress] $ rake generate && rake deploy
Leave the virtualenv
:
(my_env)[narga ~/Briefcase/octopress] $ deactivate
Meta keyworks and Meta description
By default, you won’t know how to write the keywords and description meta tags per post. Since 2.0 of Octopress, the meta description and the keywords are only applied on an individual post/page. I found the way to write my own description and keywords meta tags in the YAML front matter.
A meta description tag is automatic generated from the first lines of the post. You can override the description by setting
description
and comma separated list in quotes after the yml tagkeywords
at the top of your markdown file above the second set of dashes.
---
layout: post
title: "Example about description and keywords meta tags"
date: 2011-10-24 20:37
comments: true
categories: octopress
description: "Example about description and keywords meta tags"
keywords: "octopress features, octopress asides"
---
Auto-deploying to My Octopress Blog With Travis-CI
Read this topic to know how to make it done
Host Octopress on GitHub
GitHub offer free hosting your pages by build and publish from gh-pages
branch in your repository. If no custom domain is used, the project pages are served under a subpath of the user pages: username.github.io/projectname
. In this case, your Octopress won’t working as your configuration because it’s deploying to a subdirectory, all your images, scripts, custom fonts … may not display correctly. You can fix it with commands:
rake set_root_dir[your/path]
# To go back to publishing to the document root
rake set_root_dir[/]
Then update your _config.yml
and Rakefile
as follows:
# _config.yml
url: http://yoursite.com/your/path
# Rakefile (if deploying with rsync)
document_root = "~/yoursite.com/your/path"
Conclusion
Before migrating from WordPress to Octopress, I’m completely newbie with Ruby & Rail but I can continuing blogging with new blogging platform as well. I will updating this post in future to share my experience about Octopress – A blogging framework for hackers.