lib/octopress/draft.rb in octopress-3.0.0.rc.7 vs lib/octopress/draft.rb in octopress-3.0.0.rc.8

- old
+ new

@@ -6,12 +6,12 @@ @options['layout'] = @config['post_layout'] @options['dir'] ||= '' @options['extension'] ||= @config['post_ext'] @options['template'] ||= @config['post_template'] - if @options['type'] == 'draft' - @options['date'] = convert_date @options['date'] + if @options['date'] + @options['date'] = convert_date @options['date'] end end def path name = "#{title_slug}.#{extension}" @@ -26,17 +26,16 @@ # # Sets post options based on draft file contents # and options passed to the publish command # def publish - @options['date'] ||= read_draft_date - @options['date'] = convert_date @options['date'] + @options['date'] ||= read_draft_date || Time.now.iso8601 post_options = { 'title' => read_draft_title, - 'slug' => publish_slug, 'date' => @options['date'], + 'slug' => publish_slug, 'content' => read_draft_content, 'dir' => @options['dir'], 'type' => 'post from draft' } @@ -69,26 +68,42 @@ end # Get title from draft post file # def read_draft_title - read.match(/title:\s+(.+)?$/)[1] + match = read.match(/title:\s+(.+)?$/) + match[1] if match end # read_draft_date # def read_draft_date - read.match(/date:\s+(.+)?$/)[1] + match = read.match(/date:\s+(.+)?$/) + match[1] if match end # Get content from draft post file + # also update the draft's date configuration # def read_draft_content if @options['date'] - read.sub(/date:\s+.+?$/, "date: #{@options['date']}") + # remove date if it exists + content = read.sub(/date:\s+.+?\n/, "") + + # Insert date after title + content.sub(/(title:.+$)/i, '\1'+"\ndate: #{@options['date']}") else read end end + # Draft template defaults + # + def default_content + if @options['date'] + front_matter %w{layout title date} + else + front_matter %w{layout title} + end + end end end