Browse code

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

fhemberger authored on 04/09/2011 at 10:56:54
Showing 3 changed files
... ...
@@ -10,4 +10,5 @@ gem 'haml', '>= 3.1'
10 10
 gem 'compass', '>= 0.11'
11 11
 gem 'rubypants'
12 12
 gem 'rb-fsevent'
13
-gem 'stringex'
14 13
\ No newline at end of file
14
+gem 'stringex'
15
+gem 'unicode_utils'
15 16
\ No newline at end of file
... ...
@@ -42,6 +42,7 @@ GEM
42 42
     sass (3.1.7)
43 43
     stringex (1.3.0)
44 44
     syntax (1.0.0)
45
+    unicode_utils (1.0.0)
45 46
 
46 47
 PLATFORMS
47 48
   ruby
... ...
@@ -58,3 +59,4 @@ DEPENDENCIES
58 58
   rdiscount
59 59
   rubypants
60 60
   stringex
61
+  unicode_utils
... ...
@@ -16,8 +16,9 @@
16 16
 # - category_dir:          The subfolder to build category pages in (default is 'categories').
17 17
 # - category_title_prefix: The string used before the category name in the page title (default is
18 18
 #                          'Category: ').
19
-module Jekyll
19
+require "unicode_utils"
20 20
 
21
+module Jekyll
21 22
 
22 23
   # The CategoryIndex class creates a single category page for the specified category.
23 24
   class CategoryIndex < Page
... ...
@@ -68,7 +69,7 @@ module Jekyll
68 68
       if self.layouts.key? 'category_index'
69 69
         dir = self.config['category_dir'] || 'categories'
70 70
         self.categories.keys.each do |category|
71
-          self.write_category_index(File.join(dir, category.gsub(/_|\W/, '-')), category)
71
+          self.write_category_index(File.join(dir, UnicodeUtils.nfkd(category).gsub(/[^\x00-\x7F]/, '').gsub(/_|\W/, '-').to_s), category)
72 72
         end
73 73
 
74 74
       # Throw an exception if the layout couldn't be found.
... ...
@@ -105,7 +106,7 @@ module Jekyll
105 105
     def category_links(categories)
106 106
       dir = @context.registers[:site].config['category_dir']
107 107
       categories = categories.sort!.map do |item|
108
-        "<a class='category' href='/#{dir}/#{item.gsub(/_|\W/, '-')}/'>#{item}</a>"
108
+        "<a class='category' href='/#{dir}/#{UnicodeUtils.nfkd(item).gsub(/[^\x00-\x7F]/, '').gsub(/_|\W/, '-').to_s}/'>#{item}</a>"
109 109
       end
110 110
 
111 111
       case categories.length