From 388b509ab3938c37ae1d2fcedc4055502f50d19c Mon Sep 17 00:00:00 2001 From: Jake Zimmerman Date: Sat, 24 Dec 2022 15:45:52 -0600 Subject: [PATCH] Allow `categories: true` to make feeds for all categories --- README.md | 17 +++++++++++++++++ lib/jekyll-feed/generator.rb | 11 ++++++++++- spec/jekyll-feed_spec.rb | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 342177bf..3b10a2b9 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,13 @@ feed: - updates ``` +Or, to generate a feed for all categories: + +```yml +feed: + categories: true +``` + ## Posts limit By default the plugin limits the number of posts in the feed to 10. Simply define a new limit in your config: @@ -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 +``` + ## Excerpt Only flag Optional flag `excerpt_only` allows you to exclude post content from the Atom feed. Default value is `false` for backward compatibility. diff --git a/lib/jekyll-feed/generator.rb b/lib/jekyll-feed/generator.rb index 7a959199..8f1f571a 100644 --- a/lib/jekyll-feed/generator.rb +++ b/lib/jekyll-feed/generator.rb @@ -69,7 +69,16 @@ def collections @collections = normalize_posts_meta(@collections) @collections.each_value do |meta| - meta["categories"] = (meta["categories"] || []).to_set + 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 @collections diff --git a/spec/jekyll-feed_spec.rb b/spec/jekyll-feed_spec.rb index 41514d1f..987bd3e4 100644 --- a/spec/jekyll-feed_spec.rb +++ b/spec/jekyll-feed_spec.rb @@ -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 {