Skip to content

Commit

Permalink
Allow disabling of jekyll-feed while in development (#370)
Browse files Browse the repository at this point in the history
Merge pull request 370
  • Loading branch information
sylhare committed Jun 5, 2022
1 parent 423ca21 commit aa9ae0e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Expand Up @@ -16,6 +16,10 @@ Layout/LineEndStringConcatenationIndentation:

Lint/EmptyInPattern:
Enabled: false

Metrics/AbcSize:
IgnoredMethods:
- generate # in generator.rb

Naming/InclusiveLanguage:
Enabled: false
Expand Down
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -246,6 +246,16 @@ feed:

Note that if you include a tag that is excluded a feed will not be generated for it.

## Skip development

Use `disable_in_development: true` if you want to turn off feed generation when `jekyll.environment == "development"`,
but don't want to remove the plugin (so you don't accidentally commit the removal). Default value is `false`.

```yml
feed:
disable_in_development: true
```

## Contributing

1. Fork it (https://github.com/jekyll/jekyll-feed/fork)
Expand Down
8 changes: 8 additions & 0 deletions lib/jekyll-feed/generator.rb
Expand Up @@ -8,6 +8,10 @@ class Generator < Jekyll::Generator
# Main plugin action, called by Jekyll-core
def generate(site)
@site = site
if disabled_in_development?
Jekyll.logger.info "Jekyll Feed:", "Skipping feed generation in development"
return
end
collections.each do |name, meta|
Jekyll.logger.info "Jekyll Feed:", "Generating feed for #{name}"
(meta["categories"] + [nil]).each do |category|
Expand Down Expand Up @@ -137,5 +141,9 @@ def normalize_posts_meta(hash)
config["path"] ||= hash["posts"]["path"]
hash
end

def disabled_in_development?
config && config["disable_in_development"] && Jekyll.env == "development"
end
end
end
28 changes: 28 additions & 0 deletions spec/jekyll-feed_spec.rb
Expand Up @@ -25,7 +25,9 @@
let(:contents) { File.read(dest_dir("feed.xml")) }
let(:context) { make_context(:site => site) }
let(:feed_meta) { Liquid::Template.parse("{% feed_meta %}").render!(context, {}) }
let(:jekyll_env) { "development" }
before(:each) do
allow(Jekyll).to receive(:env).and_return(jekyll_env)
site.process
end

Expand Down Expand Up @@ -745,4 +747,30 @@ def to_s
end
end
end

context "with skip_development" do
let(:overrides) do
{
"feed" => {
"disable_in_development" => true
},
}
end

context "in production environment" do
let(:jekyll_env) { "production" }

it "generates a feed as normal" do
expect(Pathname.new(dest_dir("feed.xml"))).to exist
end
end

context "in development environment" do
let(:jekyll_env) { "development" }

it "does not generate a feed" do
expect(Pathname.new(dest_dir("feed.xml"))).not_to exist
end
end
end
end

0 comments on commit aa9ae0e

Please sign in to comment.