Consistent case of URLs in Octopress
Question
I have my Octopress permalinks and category set as:
permalink: /blog/:categories/:title/
category_dir: blog
Examples _post/2013-05-20-BeefStew.markdown
---
layout: post
title: "Beef & Guinness Stew with Dumplings"
date: 2013-05-20 09:24
comments: true
categories: Cooking
The permalink for this page is /blog/Cooking/BeefStew/
, the category page link is /blog/cooking/
.
I would really like to get the category case consistent. How do I get the permalink to use a lowercase (downcase) of :categories?
I have tried making Octopress use the latest jekyll which I thought had downcased the full permalink but it broke the Octopress build process.
Also tried permalink: /blog/(:categories).downcase/:title/
but that just created links of /blog/(Cooking).downcase/BeefStew/
.
Solution
Monkey patching the url used in Jekyll can achieve the required result.
# MonkeyPatch to lowercase (downcase) the URL
# Octopress (Jekyll 0.12.1)
module Jekyll
class Post
# Copy the #url method to #old_url, so we can redefine #url
# method.
alias_method :old_url, :url
def url
a = old_url.downcase
end
end
end
I have made this plugin available on Github, it will create urls which match:
Post URL : /blog/cooking/beefstew/
Category URL : /blog/cooking/
.