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 skipping generation in development #346

Closed
Closed
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ feed:

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

## Skip development

Use `skip_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:
skip_development: true
Copy link
Member

Choose a reason for hiding this comment

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

I think we could improve this name a bit. What do you think about disable_in_development or skip_in_development?

```

## Contributing

1. Fork it (https://github.com/jekyll/jekyll-feed/fork)
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll-feed/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Generator < Jekyll::Generator
# Main plugin action, called by Jekyll-core
def generate(site)
@site = site
return if config["skip_development"] == true && Jekyll.env == "development"
Copy link
Member

Choose a reason for hiding this comment

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

Let's log in this case so it's clear to the user what's happening. Something like:

Jekyll.logger.info "Jekyll Feed:", "Skipping feed generation in development"


collections.each do |name, meta|
Jekyll.logger.info "Jekyll Feed:", "Generating feed for #{name}"
(meta["categories"] + [nil]).each do |category|
Expand Down
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 @@ -738,4 +740,30 @@ def to_s
end
end
end

context "with skip_development" do
let(:overrides) do
{
"feed" => {
"skip_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