Skip to content

Commit e7e6fdf

Browse files
authored
Allow creating slugs for emoji characters. (#129)
Merge pull request 129
1 parent 11a02db commit e7e6fdf

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

docs/configuration.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jekyll-archives:
2525
#### Optional settings
2626
- [Default layout (`layout`)](#default-layout)
2727
- [Permalinks (`permalinks`)](#permalinks)
28+
- [Slug configuration (`slug_mode`)](#slug-configuration)
2829

2930
---
3031

@@ -121,3 +122,15 @@ permalinks:
121122
month: '/archives/month/:year-:month/'
122123
tag: '/archives/tag/:name/'
123124
```
125+
126+
#### Slug Configuration
127+
128+
Archives of tags and categories are by default generated by *slugifying* the tag or category name.
129+
You can configure the result of this process by setting the `slug_mode` key to any of the
130+
[modes expected by Jekyll](https://jekyllrb.com/docs/liquid/filters/#options-for-the-slugify-filter)
131+
132+
##### Sample values
133+
134+
```yml
135+
slug_mode: latin
136+
```

lib/jekyll-archives/archive.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ def initialize(site, title, type, posts)
3030
@type = type
3131
@title = title
3232
@config = site.config["jekyll-archives"]
33-
34-
# Generate slug if tag or category
35-
# (taken from jekyll/jekyll/features/support/env.rb)
36-
@slug = Utils.slugify(title) if title.is_a? String
33+
@slug = slugify_string_title
3734

3835
# Use ".html" for file extension and url for path
3936
@ext = File.extname(relative_path)
@@ -122,6 +119,18 @@ def relative_path
122119
def inspect
123120
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
124121
end
122+
123+
private
124+
125+
# Generate slug if @title attribute is a string.
126+
#
127+
# Note: mode other than those expected by Jekyll returns the given string after
128+
# downcasing it.
129+
def slugify_string_title
130+
return unless title.is_a?(String)
131+
132+
Utils.slugify(title, :mode => @config["slug_mode"])
133+
end
125134
end
126135
end
127136
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Pretty Slugs
3+
category: 💎
4+
---
5+
6+
Post with 💎 category.

test/test_jekyll_archives.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ class TestJekyllArchives < Minitest::Test
4848
end
4949
end
5050

51+
context "the jekyll-archives plugin with a custom slug mode" do
52+
setup do
53+
# slug mode other than those expected by Jekyll returns the given string after
54+
# downcasing it.
55+
@site = fixture_site("jekyll-archives" => {
56+
"slug_mode" => "raw",
57+
"enabled" => true,
58+
})
59+
@site.read
60+
@archives = Jekyll::Archives::Archives.new(@site.config)
61+
end
62+
63+
should "generate slugs using the mode specified" do
64+
@archives.generate(@site)
65+
assert archive_exists? @site, "category/💎/index.html"
66+
end
67+
end
68+
5169
context "the jekyll-archives plugin with custom layout path" do
5270
setup do
5371
@site = fixture_site("jekyll-archives" => {
@@ -116,7 +134,7 @@ class TestJekyllArchives < Minitest::Test
116134
end
117135

118136
should "populate the {{ site.archives }} tag in Liquid" do
119-
assert_equal 12, read_file("length.html").to_i
137+
assert_equal 16, read_file("length.html").to_i
120138
end
121139
end
122140

0 commit comments

Comments
 (0)