Skip to content

Commit d9469c8

Browse files
author
Matthew Loberg
committed
Add source and config options to post command
Update post command to respect any custom Jekyll source.
1 parent 7b71ac4 commit d9469c8

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/jekyll/commands/post.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def self.options
1717
['extension', '-x EXTENSION', '--extension EXTENSION', 'Specify the file extension'],
1818
['layout', '-l LAYOUT', '--layout LAYOUT', "Specify the post layout"],
1919
['force', '-f', '--force', 'Overwrite a post if it already exists'],
20-
['date', '-d DATE', '--date DATE', 'Specify the post date']
20+
['date', '-d DATE', '--date DATE', 'Specify the post date'],
21+
['config', '--config CONFIG_FILE[,CONFIG_FILE2,...]', Array, 'Custom configuration file'],
22+
['source', '-s', '--source SOURCE', 'Custom source directory'],
2123
]
2224
end
2325

@@ -27,7 +29,7 @@ def self.process(args = [], options = {})
2729

2830
post = PostFileInfo.new params
2931

30-
Compose::FileCreator.new(post, params.force?).create!
32+
Compose::FileCreator.new(post, params.force?, params.source).create!
3133
end
3234

3335

spec/post_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,37 @@
8282
expect(File.read(path)).to match(/layout: post/)
8383
end
8484
end
85+
86+
context 'when a configuration file exists' do
87+
let(:config) { source_dir('_config.yml') }
88+
let(:posts_dir) { Pathname.new source_dir('site', '_posts') }
89+
90+
before(:each) do
91+
File.open(config, 'w') do |f|
92+
f.write(%{
93+
source: site
94+
})
95+
end
96+
end
97+
98+
after(:each) do
99+
FileUtils.rm(config)
100+
end
101+
102+
it 'should use source directory set by config' do
103+
expect(path).not_to exist
104+
capture_stdout { described_class.process(args) }
105+
expect(path).to exist
106+
end
107+
end
108+
109+
context 'when source option is set' do
110+
let(:posts_dir) { Pathname.new source_dir('site', '_posts') }
111+
112+
it 'should use source directory set by command line option' do
113+
expect(path).not_to exist
114+
capture_stdout { described_class.process(args, 'source' => 'site') }
115+
expect(path).to exist
116+
end
117+
end
85118
end

0 commit comments

Comments
 (0)