Skip to content

Commit 4b2fd0d

Browse files
jandudulskijekyllbot
authored andcommitted
Add date to front matter when publish (#54)
Merge pull request 54
1 parent e09fe98 commit 4b2fd0d

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

lib/jekyll-compose/file_info.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ def file_name
99
"#{name}.#{params.type}"
1010
end
1111

12-
def content
12+
def content(custom_front_matter = {})
1313
front_matter = YAML.dump({
1414
"layout" => params.layout,
1515
"title" => params.title,
16-
})
16+
}.merge(custom_front_matter))
1717

1818
front_matter + "---\n"
1919
end

lib/jekyll/commands/post.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ def file_name
5454
def _date_stamp
5555
@params.date.strftime "%Y-%m-%d"
5656
end
57+
58+
def _time_stamp
59+
@params.date.strftime("%Y-%m-%d %H:%M %z")
60+
end
61+
62+
def content(custom_front_matter = {})
63+
super({ "date" => _time_stamp }.merge(custom_front_matter))
64+
end
5765
end
5866
end
5967
end

spec/file_info_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,29 @@
4545
expect(file_info.content).to eq(expected_result)
4646
end
4747
end
48+
49+
context "with custom values" do
50+
let(:expected_result) do
51+
<<-CONTENT.gsub(%r!^\s+!, "")
52+
---
53+
layout: post
54+
title: A test
55+
foo: bar
56+
---
57+
CONTENT
58+
end
59+
60+
let(:parsed_args) do
61+
Jekyll::Compose::ArgParser.new(
62+
["A test arg parser"],
63+
{}
64+
)
65+
end
66+
67+
it "does not wrap the title in quotes" do
68+
file_info = described_class.new parsed_args
69+
expect(file_info.content("title" => "A test", "foo" => "bar")).to eq(expected_result)
70+
end
71+
end
4872
end
4973
end

spec/post_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
let(:args) { [name] }
44
let(:posts_dir) { Pathname.new source_dir("_posts") }
55
let(:datestamp) { Time.now.strftime("%Y-%m-%d") }
6+
let(:timestamp) { Time.now.strftime("%Y-%m-%d %H:%M %z") }
67
let(:filename) { "#{datestamp}-a-test-post.md" }
78
let(:path) { posts_dir.join(filename) }
89

@@ -30,6 +31,7 @@
3031
expect(path).not_to exist
3132
capture_stdout { described_class.process(args, { "date" => "2012-3-4" }) }
3233
expect(path).to exist
34+
expect(File.read(path)).to match(%r!date: 2012-03-04 00:00 \+0000!)
3335
end
3436

3537
it "creates the post with a specified extension" do

0 commit comments

Comments
 (0)