Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
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
end
end

Expand Down