Skip to content

Commit

Permalink
Add draft and post front matter support.
Browse files Browse the repository at this point in the history
able to add draft and post front matter in _config.yml in Jekyll
directory.
adopted from toshimaru's PR
(jekyll#41)
  • Loading branch information
mofhu committed Mar 5, 2017
1 parent 1c5d58f commit 853caf1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/jekyll-compose/file_info.rb
Expand Up @@ -9,11 +9,11 @@ def file_name
"#{name}.#{params.type}"
end

def content
def content(addtional_front_matter = {})
front_matter = YAML.dump({
'layout' => params.layout,
'title' => params.title,
})
}.merge(addtional_front_matter))

front_matter + "---\n"
end
Expand Down
5 changes: 5 additions & 0 deletions lib/jekyll/commands/draft.rb
Expand Up @@ -40,6 +40,11 @@ def resource_type
def path
"_drafts/#{file_name}"
end

def content
post_front_matter = Jekyll.configuration["post_front_matter"]
post_front_matter ? super(post_front_matter) : super
end
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/jekyll/commands/post.rb
Expand Up @@ -55,6 +55,11 @@ def file_name
def _date_stamp
@params.date.strftime '%Y-%m-%d'
end

def content
post_front_matter = Jekyll.configuration["post_front_matter"]
post_front_matter ? super(post_front_matter) : super
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/draft_spec.rb
Expand Up @@ -50,6 +50,8 @@
it 'creates a new draft with the specified layout' do
capture_stdout { described_class.process(args, 'layout' => 'other-layout') }
expect(File.read(path)).to match(/layout: other-layout/)
expect(File.read(path)).to match(/description: my description/)
expect(File.read(path)).to mathc(/category: /)
end

context 'when the draft already exists' do
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/_config.yml
@@ -0,0 +1,3 @@
post_front_matter:
description: my description
category:
8 changes: 8 additions & 0 deletions spec/post_spec.rb
Expand Up @@ -5,6 +5,7 @@
let(:datestamp) { Time.now.strftime('%Y-%m-%d') }
let(:filename) { "#{datestamp}-a-test-post.md" }
let(:path) { posts_dir.join(filename) }
let(:jekyll_config) {YAML.load_file('../fixtures/_config.yml')}

before(:all) do
FileUtils.mkdir_p source_dir unless File.directory? source_dir
Expand Down Expand Up @@ -44,6 +45,13 @@
expect(File.read(path)).to match(/layout: other-layout/)
end

it 'creates a new page with the specified config' do
expect(Jekyll).to receive(:configuration).and_return(jekyll_config)
capture_stdout { described_class.process(args) }
expect(File.read(path)).to match(/description: my description/)
expect(File.read(path)).to match(/category: /)
end

it 'should write a helpful message when successful' do
output = capture_stdout { described_class.process(args) }
expect(output).to eql("New post created at _posts/#{filename}.\n")
Expand Down

0 comments on commit 853caf1

Please sign in to comment.