Skip to content

Commit

Permalink
Allow additional front matter for Post (#41)
Browse files Browse the repository at this point in the history
Merge pull request 41
  • Loading branch information
toshimaru authored and jekyllbot committed Oct 9, 2018
1 parent 6046b41 commit 14e6e54
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/jekyll/commands/post.rb
Expand Up @@ -64,8 +64,17 @@ def _time_stamp
end

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

private

def compose_config
@compose_config ||= Jekyll.configuration["jekyll_compose"] || {}
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

0 comments on commit 14e6e54

Please sign in to comment.