Xit0

Random Scribblings of a Linux Enthusiast

Remove Redundant /blog Prefix From Octopress Website

Octopress, by default, generates static websites with a /blog prefix attached to categories, archives and post URLs. This is particularly annoying when the blog is hosted at blog.yourdomain.tld and have funny URLs like blog.yourdomain.tld/blog/archives.

To get rid of this, I’ve created a clone of the classic Octopress theme with the necessary changes. It also renames Blog to Home in the navigation bar.

To install and use octopress-classic-no-blog theme:

1
2
3
$ cd octopress
$ git clone git@github.com:pmirshad/octopress-classic-no-blog.git .themes/octopress-classic-no-blog
$ rake install['octopress-classic-no-blog']

Changes are also required in _config.yml. permalink, category_dir, pagination_dir properties have to be modified to remove the blog prefix

1
2
3
4
5
6
7
8
#permalink: /blog/:year/:month/:day/:title/
permalink: /:year/:month/:day/:title/

#category_dir: blog/categories
category_dir: categories

#pagination_dir: blog  # Directory base for pagination URLs eg. /blog/page/2/
pagination_dir:       # Directory base for pagination URLs eg. /page/2/

After installing the theme and fixing _config.yml, generate the blog.

1
$ rake generate

DIY for other themes

To achieve this for other themes, the following modifications should suffice. [Assumption: The theme is already installed and you are familiar with diffs]

1
cd octopress/

Move archives folder from source/blog to source/.

1
mv -v source/blog/archives source/

Edit source/_includes/custom/navigation.html to fix navigation URLs.

1
2
3
4
-  <li><a href="/">Blog</a></li>
-  <li><a href="/blog/archives">Archives</a></li>
+  <li><a href="/">Home</a></li>
+  <li><a href="/archives">Archives</a></li>

Edit source/index.html to fix the Archives page URL.

1
2
-    <a href="/blog/archives">Blog Archives</a>
+    <a href="/archives">Archives</a>

A theme in the .themes folder can be modified similarly, but will have to be reinstalled with the rake install['theme-name'] command afterwards.

Comments