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..76ef0618 100644 --- a/lib/jekyll-feed/generator.rb +++ b/lib/jekyll-feed/generator.rb @@ -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 @@ -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 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 {