MDLog:/sysadmin

The Journal Of A Linux Sysadmin

Finally Migrated to Octopress

| Comments

For a while now, I wanted to migrate my blog from Wordpress to Octopress, but for some reason I kept putting it on the shelf and not doing it. (let’s say because of all those client related projects…). Finally last weekend I’ve completed the migration and I’m really excited to get back to blogging after this. This post is meant to capture some of the issues I’ve encountered during the migration and how to fix them. This is not a full how to migrate post, as there are many such great articles available already.

Migrate old blog posts.

Believe it or not, I had 364 blog posts when I started the migration. Meaning a lot of energy was spent in importing those old articles. I’ve used exitwp to convert the wordpress-xml export of the blog posts; and this produced a reasonably good result. Still I had to run some fixes…

  • for code blocks:
1
 perl -pi -e 's/([^\`]|^)(\`)([^\`]|$)/$1\n\`\`\`\n$3/g' *
  • to enable comments (as ‘comments: true’ was missing from all posts)
1
2
find source/_posts/ -type f -print0 | xargs -0 -I file sed -i '' '2 i \
  comments: true' file

Categories/Tags/URLs

Enabled the octopress category list plugin and tags plugin, that you can see in the sidebar. Since I had already tags and categories on all posts it was very important to keep the same urls and not break them. Same thing for regular posts urls. Here are the relevant settings form the octopress config file:

1
2
3
4
5
6
root: /
permalink: /:year/:month/:day/:title/

category_dir: category

tag_dir: "tag"

Just keep in mind that if you have many tags as I do, the generation of the pages will increase a lot after you enable the tags plugin. You’ve been warned!

Disqus comments

Not working at all… I’ve wrote a post specifically about this; check it out here

Feed Url

My wordpress blog has been around for a while (6years more or less) and even if I’ve always used feedburner for my feed, but for some strange reason I’ve always used my own feed url. This of course was no longer working with octopress, hence I had to setup a rewrite rule to not break everyone’s feed reader:

1
2
3
4
5
RewriteEngine On
Options +FollowSymLinks -Multiviews

# Feed url
RewriteRule ^feed/?$ atom.xml [QSA,L]

Rewrite non-www to www

This was done automatically by wordpress, but octopress will serve just fine the non-www domain. This can cause issues with search engines and such, so I wanted the same behaviour. Apache again to the rescue:

1
2
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule $ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]

Apache optimizations, caching, compression, etc

After you generated your octopress site, everything is static and fast by default. Still, you want to make sure that apache has some basic caching and compression settings to make it even better. Here are the relevant parts from my config:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#### CACHING ####
<IfModule mod_expires.c>
ExpiresActive On

# 1 MONTH
<FilesMatch "\.(ico|gif|jpe?g|png|flv|pdf|swf|mov|mp3|wmv|ppt)$">
  ExpiresDefault A2419200
  Header append Cache-Control "public"
</FilesMatch>

# 3 DAYS
<FilesMatch "\.(xml|txt|html|htm|js|css)$">
  ExpiresDefault A259200
  Header append Cache-Control "private, must-revalidate"
</FilesMatch>

# NEVER CACHE
<FilesMatch "\.(php|cgi|pl)$">
  ExpiresDefault A0
  Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
  Header set Pragma "no-cache"
</FilesMatch>
</IfModule>

### Compression ####
<IfModule mod_deflate.c>
    <IfModule mod_setenvif.c>
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    </IfModule>
    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
    </IfModule>
</IfModule>

Isolated when working on a new post

If you have many posts, the generation of the octopress site will be extremely slow (in my case it takes about 2mins for a full generate) and this makes it basically impossible to work with any new post and see the feedback locally with preview. The solution is well documented and it works by isolating your single post while working on it, and when you are done you integrate back all the other posts before publishing them:

1
2
rake new_post['Finally Migrated to Octopress']
rake isolate[finally-migrated-to-octopress]

and now rake generate and rake preview will only work with the new post. Finally when done and ready to publish the awesome new post on the internets:

1
2
3
rake integrate
rake generate
rake deploy

Others

  • some small customisations to the theme (colours and such)
  • about me and contact custom asides.
  • fix the github aside (updated to work with their latest api version and actually return the repos)
  • and of course the contact form (using a wufoo form)

Comments