Skip to content

Allow disabling of jekyll-feed while in development #370

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

Merged
merged 5 commits into from
Jun 5, 2022
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
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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