From 44bc5daea27b250e7a92f91813c88fe03be37e7a Mon Sep 17 00:00:00 2001 From: Juan Ignacio Donoso Date: Mon, 29 Dec 2014 23:43:55 -0300 Subject: [PATCH] publish command receive the draft path --- lib/jekyll/commands/publish.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/jekyll/commands/publish.rb b/lib/jekyll/commands/publish.rb index 2dd5157..3f7355e 100644 --- a/lib/jekyll/commands/publish.rb +++ b/lib/jekyll/commands/publish.rb @@ -3,7 +3,7 @@ module Commands class Publish < Command def self.init_with_program(prog) prog.command(:publish) do |c| - c.syntax 'publish NAME' + c.syntax 'publish DRAFT_PATH' c.description 'Moves a draft into the _posts directory and sets the date' c.option 'date', '-d DATE', '--date DATE', 'Specify the post date' @@ -15,16 +15,18 @@ def self.init_with_program(prog) end def self.process(args, options = {}) - raise ArgumentError.new('You must specify a name.') if args.empty? - + raise ArgumentError.new('You must specify a draft path.') if args.empty? + date = options["date"].nil? ? Date.today : Date.parse(options["date"]) - file = args.shift + draft_path = args.shift + + raise ArgumentError.new("There was no draft found at '#{draft_path}'.") unless File.exist? draft_path - post_path = post_name(date, file) - FileUtils.mv(draft_name(file), post_path) + post_path = post_name(date, draft_name(draft_path)) + FileUtils.mv(draft_path, post_path) - puts "Draft #{file} was published to ./#{post_path}" - end + puts "Draft #{draft_path} was published to ./#{post_path}" + end # Internal: Gets the filename of the post to be created # @@ -33,8 +35,8 @@ def self.post_name(date, name) "_posts/#{date.strftime('%Y-%m-%d')}-#{name}" end - def self.draft_name(name) - "_drafts/#{name}" + def self.draft_name(path) + File.basename(path) end end