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

add support for categories frontmatter #153

Merged
merged 17 commits into from
Jun 23, 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
2 changes: 1 addition & 1 deletion lib/jekyll-feed/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def generate_tag_feed(tags_pool, tags_path)
tags_pool.each do |tag|
# allow only tags with basic alphanumeric characters and underscore to keep
# feed path simple.
next if tag =~ %r![^a-zA-Z0-9_]!
next if %r![^a-zA-Z0-9_]!.match?(tag)

Jekyll.logger.info "Jekyll Feed:", "Generating feed for posts tagged #{tag}"
path = "#{tags_path}#{tag}.xml"
Expand Down
2 changes: 0 additions & 2 deletions spec/fixtures/_posts/2014-03-02-march-the-second.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
image: https://cdn.example.org/absolute.png?h=188&w=250
category: news
tags:
- test
---

March the second!
1 change: 1 addition & 0 deletions spec/fixtures/_posts/2015-05-12-liquid.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
categories: [first, second, third]
---

{% capture liquidstring %}
Expand Down
14 changes: 13 additions & 1 deletion spec/jekyll-feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@
end
end

context "with 'categories' or 'category' or 'tags' key in the front matter" do
let(:feed) { RSS::Parser.parse(contents) }
let(:entry_with_single_category) { feed.items.find { |i| i.title.content == "March The Second" } }
let(:entry_with_multiple_categories) { feed.items.find { |i| i.title.content == "Liquid" } }
let(:entry_with_multiple_categories_and_tags) { feed.items.find { |i| i.title.content == "Sparkling Title" } }

it "generates the feed correctly" do
expect(entry_with_single_category.categories.map(&:term)).to eql(%w(news))
expect(entry_with_multiple_categories.categories.map(&:term)).to eql(%w(first second third))
expect(entry_with_multiple_categories_and_tags.categories.map(&:term)).to eql(["updates", "jekyll", "\"/><VADER>", "test"])
end
end

context "changing the file path via collection meta" do
let(:overrides) do
{
Expand Down Expand Up @@ -526,7 +539,6 @@
expect(Pathname.new(dest_dir("feed/by_tag/success.xml"))).to exist

expect(tags_feed_test).to match "/2013/12/12/dec-the-second.html"
expect(tags_feed_test).to match "/2014/03/02/march-the-second.html"
expect(tags_feed_test).to match "/2014/03/04/march-the-fourth.html"
expect(tags_feed_test).to match "/2015/01/18/jekyll-last-modified-at.html"
expect(tags_feed_test).to match "/2015/05/12/pre.html"
Expand Down