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 categories: true to make feeds for all categories #379

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ feed:
- updates
```

Or, to generate a feed for all categories:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to explain that in the current implementation, this means that each collection will get its own category feed. This operates differently than tag-based feeds where they unify all documents from any collection into a single feed.


```yml
feed:
categories: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 24 of generator.rb, we have special handling for config["tags"]. Do we intend to only generate collection-level categories?

```

## Posts limit

By default the plugin limits the number of posts in the feed to 10. Simply define a new limit in your config:
Expand Down Expand Up @@ -193,6 +200,16 @@ feed:
- updates
```

Or pass `categories: true` to generate a feed for all categories:

```yml
feed:
collections:
changes:
path: "/changes.atom"
categories: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test for this? It seems like we could over-generate. That is we could generate a category feed which has zero entries since a collection doesn't have any documents with a category that is only present in another collection.

  1. Collection "posts" has categories "A" and "B"
  2. Collection "archives" has categories "C"
  3. Will we generate /feed/archives/A.xml with zero entries?

```

## Excerpt Only flag

Optional flag `excerpt_only` allows you to exclude post content from the Atom feed. Default value is `false` for backward compatibility.
Expand Down
15 changes: 14 additions & 1 deletion lib/jekyll-feed/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def collections

@collections = normalize_posts_meta(@collections)
@collections.each_value do |meta|
meta["categories"] = (meta["categories"] || []).to_set
normalize_categories(meta)
end

@collections
Expand Down Expand Up @@ -142,6 +142,19 @@ def normalize_posts_meta(hash)
hash
end

def normalize_categories(meta)
meta_categories = meta["categories"]
for_collection = case meta_categories
when Array
meta_categories
when true
@site.categories.keys
else
[]
end
meta["categories"] = for_collection.to_set
end

def disabled_in_development?
config && config["disable_in_development"] && Jekyll.env == "development"
end
Expand Down
14 changes: 14 additions & 0 deletions spec/jekyll-feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,20 @@ def to_s
end
end

context "with top-level post categories (using true to mean all)" do
let(:overrides) do
{
"feed" => { "categories" => true }
}
end

it "outputs feeds for all categories" do
site.categories.each_key do |category|
expect(Pathname.new(dest_dir("feed/#{category}.xml"))).to exist
end
end
end

context "with collection-level post categories" do
let(:overrides) do
{
Expand Down