Improved support for non Latin characters in category names. Fixes #128

This commit is contained in:
Chun-wei Kuo 2011-09-05 18:07:40 +08:00
parent 4c21e69093
commit 7e976cbc60

View File

@ -1,3 +1,5 @@
# encoding: utf-8
#
# Jekyll category page generator. # Jekyll category page generator.
# http://recursive-design.com/projects/jekyll-plugins/ # http://recursive-design.com/projects/jekyll-plugins/
# #
@ -16,7 +18,6 @@
# - category_dir: The subfolder to build category pages in (default is 'categories'). # - category_dir: The subfolder to build category pages in (default is 'categories').
# - category_title_prefix: The string used before the category name in the page title (default is # - category_title_prefix: The string used before the category name in the page title (default is
# 'Category: '). # 'Category: ').
require "unicode_utils"
module Jekyll module Jekyll
@ -69,7 +70,7 @@ module Jekyll
if self.layouts.key? 'category_index' if self.layouts.key? 'category_index'
dir = self.config['category_dir'] || 'categories' dir = self.config['category_dir'] || 'categories'
self.categories.keys.each do |category| self.categories.keys.each do |category|
self.write_category_index(File.join(dir, UnicodeUtils.nfkd(category).gsub(/[^\x00-\x7F]/, '').gsub(/_|\W/, '-').gsub(/-{2,}/, '-').to_s), category) self.write_category_index(File.join(dir, category.gsub(/_|\P{Word}/, '-').gsub(/-{2,}/, '-')), category)
end end
# Throw an exception if the layout couldn't be found. # Throw an exception if the layout couldn't be found.
@ -106,7 +107,7 @@ module Jekyll
def category_links(categories) def category_links(categories)
dir = @context.registers[:site].config['category_dir'] dir = @context.registers[:site].config['category_dir']
categories = categories.sort!.map do |item| categories = categories.sort!.map do |item|
"<a class='category' href='/#{dir}/#{UnicodeUtils.nfkd(item).gsub(/[^\x00-\x7F]/, '').gsub(/_|\W/, '-').gsub(/-{2,}/, '-').to_s}/'>#{item}</a>" "<a class='category' href='/#{dir}/#{item.gsub(/_|\P{Word}/, '-').gsub(/-{2,}/, '-')}/'>#{item}</a>"
end end
case categories.length case categories.length