Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion lib/jekyll-archives/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def initialize(site, title, type, posts)

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

# Use ".html" for file extension and url for path
@ext = File.extname(relative_path)
Expand Down Expand Up @@ -118,6 +118,13 @@ def relative_path
path
end

# Return the mode to use for generating slugs.
#
# Returns a symbol or nil.
def slug_mode
@config["slug_mode"].to_sym if @config["slug_mode"]
end

# Returns the object as a debug String.
def inspect
"#<Jekyll:Archive @type=#{@type} @title=#{@title} @data=#{@data.inspect}>"
Expand Down
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.
18 changes: 17 additions & 1 deletion test/test_jekyll_archives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ class TestJekyllArchives < Minitest::Test
end
end

context "the jekyll-archives plugin with a custom slug mode" do
setup do
@site = fixture_site("jekyll-archives" => {
"slug_mode" => "pretty",
"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 +132,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
end
end

Expand Down