Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creating slugs for emoji characters. #129

Merged
merged 7 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jekyll-archives:
#### Optional settings
- [Default layout (`layout`)](#default-layout)
- [Permalinks (`permalinks`)](#permalinks)
- [Slug configuration (`slug_mode`)](#slug-configuration)

---

Expand Down Expand Up @@ -121,3 +122,15 @@ permalinks:
month: '/archives/month/:year-:month/'
tag: '/archives/tag/:name/'
```

#### Slug Configuration

Archives of tags and categories are by default generated by *slugifying* the tag or category name.
You can configure the result of this process by setting the `slug_mode` key to any of the
[modes expected by Jekyll](https://jekyllrb.com/docs/liquid/filters/#options-for-the-slugify-filter)

##### Sample values

```yml
slug_mode: latin
```
17 changes: 13 additions & 4 deletions lib/jekyll-archives/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ def initialize(site, title, type, posts)
@type = type
@title = title
@config = site.config["jekyll-archives"]

# Generate slug if tag or category
# (taken from jekyll/jekyll/features/support/env.rb)
@slug = Utils.slugify(title) if title.is_a? String
@slug = slugify_string_title

# Use ".html" for file extension and url for path
@ext = File.extname(relative_path)
Expand Down Expand Up @@ -122,6 +119,18 @@ def relative_path
def inspect
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
end

private

# Generate slug if @title attribute is a string.
#
# Note: mode other than those expected by Jekyll returns the given string after
# downcasing it.
def slugify_string_title
return unless title.is_a?(String)

Utils.slugify(title, :mode => @config["slug_mode"])
end
end
end
end
6 changes: 6 additions & 0 deletions test/source/_posts/2018-11-05-pretty-slugs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Pretty Slugs
category: 💎
---

Post with 💎 category.
20 changes: 19 additions & 1 deletion test/test_jekyll_archives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ class TestJekyllArchives < Minitest::Test
end
end

context "the jekyll-archives plugin with a custom slug mode" do
setup do
# slug mode other than those expected by Jekyll returns the given string after
# downcasing it.
@site = fixture_site("jekyll-archives" => {
"slug_mode" => "raw",
"enabled" => true,
})
@site.read
@archives = Jekyll::Archives::Archives.new(@site.config)
end

should "generate slugs using the mode specified" do
@archives.generate(@site)
assert archive_exists? @site, "category/💎/index.html"
end
end

context "the jekyll-archives plugin with custom layout path" do
setup do
@site = fixture_site("jekyll-archives" => {
Expand Down Expand Up @@ -116,7 +134,7 @@ class TestJekyllArchives < Minitest::Test
end

should "populate the {{ site.archives }} tag in Liquid" do
assert_equal 12, read_file("length.html").to_i
assert_equal 16, read_file("length.html").to_i
ashmaroli marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down