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 additional front matter for Post #41

Merged
merged 7 commits into from Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/jekyll/commands/post.rb
Expand Up @@ -64,8 +64,18 @@ def _time_stamp
end

def content(custom_front_matter = {})
if jekyll_compose_config && jekyll_compose_config["post_default_front_matter"]
custom_front_matter.merge!(jekyll_compose_config["post_default_front_matter"])
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 merge! only a valid config:

def content(custom_front_matter = {})
  default_front_matter = compose_config["post_default_front_matter"]
  custom_front_matter.merge!(default_front_matter) if default_front_matter.is_a?(Hash)

  super({ "date" => _time_stamp }.merge(custom_front_matter))
end

end

super({ "date" => _time_stamp }.merge(custom_front_matter))
end

private

def jekyll_compose_config
@jekyll_compose_config ||= Jekyll.configuration["jekyll_compose"]
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 default the config to a hash so that we can avoid a nil check in method #content above:

# Returns a Hash
def compose_config
  @compose_config ||= Jekyll.configuration["jekyll_compose"] || {}
end

Copy link
Member

Choose a reason for hiding this comment

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

This has been adressed in #76

end
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion spec/post_spec.rb
Expand Up @@ -113,15 +113,25 @@
expect(path).to exist
end

context "auto_open editor is set" do
context "configuration is set" do
let(:posts_dir) { Pathname.new source_dir("_posts") }
let(:config_data) do
%(
jekyll_compose:
auto_open: true
post_default_front_matter:
description: my description
category:
)
end

it "creates post with the specified config" do
capture_stdout { described_class.process(args) }
post = File.read(path)
expect(post).to match(%r!description: my description!)
expect(post).to match(%r!category: !)
end

context "env variable EDITOR is set up" do
before { ENV["EDITOR"] = "vim" }

Expand Down