Don't require date in draft filenames.
This commit is contained in:
parent
daa9e11994
commit
1ac46b17c4
|
@ -50,11 +50,8 @@ Given /^I have an? (.*) directory$/ do |dir|
|
||||||
FileUtils.mkdir_p(dir)
|
FileUtils.mkdir_p(dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |type, direction, folder, table|
|
Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, direction, folder, table|
|
||||||
subdir = "_#{type}s"
|
|
||||||
|
|
||||||
table.hashes.each do |post|
|
table.hashes.each do |post|
|
||||||
date = Date.strptime(post['date'], '%m/%d/%Y').strftime('%Y-%m-%d')
|
|
||||||
title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
|
title = post['title'].downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, '-')
|
||||||
|
|
||||||
if direction && direction == "in"
|
if direction && direction == "in"
|
||||||
|
@ -63,7 +60,14 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |type, direct
|
||||||
after = folder || '.'
|
after = folder || '.'
|
||||||
end
|
end
|
||||||
|
|
||||||
path = File.join(before || '.', subdir, after || '.', "#{date}-#{title}.#{post['type'] || 'textile'}")
|
ext = post['type'] || 'textile'
|
||||||
|
|
||||||
|
if "draft" == status
|
||||||
|
path = File.join(before || '.', '_drafts', after || '.', "#{title}.#{ext}")
|
||||||
|
else
|
||||||
|
date = Date.strptime(post['date'], '%m/%d/%Y').strftime('%Y-%m-%d')
|
||||||
|
path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{ext}")
|
||||||
|
end
|
||||||
|
|
||||||
matter_hash = {}
|
matter_hash = {}
|
||||||
%w(title layout tag tags category categories published author).each do |key|
|
%w(title layout tag tags category categories published author).each do |key|
|
||||||
|
|
|
@ -33,6 +33,7 @@ require 'jekyll/convertible'
|
||||||
require 'jekyll/layout'
|
require 'jekyll/layout'
|
||||||
require 'jekyll/page'
|
require 'jekyll/page'
|
||||||
require 'jekyll/post'
|
require 'jekyll/post'
|
||||||
|
require 'jekyll/draft'
|
||||||
require 'jekyll/filters'
|
require 'jekyll/filters'
|
||||||
require 'jekyll/static_file'
|
require 'jekyll/static_file'
|
||||||
require 'jekyll/errors'
|
require 'jekyll/errors'
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
module Jekyll
|
||||||
|
|
||||||
|
class Draft < Post
|
||||||
|
|
||||||
|
# Valid post name regex (no date)
|
||||||
|
MATCHER = /^(.*)(\.[^.]+)$/
|
||||||
|
|
||||||
|
# Extract information from the post filename.
|
||||||
|
#
|
||||||
|
# name - The String filename of the post file.
|
||||||
|
#
|
||||||
|
# Returns nothing.
|
||||||
|
def process(name)
|
||||||
|
slug, ext = *name.match(MATCHER)
|
||||||
|
self.date = File.mtime(File.join(@base, name))
|
||||||
|
self.slug = slug
|
||||||
|
self.ext = ext
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -30,12 +30,11 @@ module Jekyll
|
||||||
# site - The Site.
|
# site - The Site.
|
||||||
# base - The String path to the dir containing the post file.
|
# base - The String path to the dir containing the post file.
|
||||||
# name - The String filename of the post file.
|
# name - The String filename of the post file.
|
||||||
# subdir - The String path to the subdirectory.
|
|
||||||
#
|
#
|
||||||
# Returns the new Post.
|
# Returns the new Post.
|
||||||
def initialize(site, source, dir, name, subdir = '_posts')
|
def initialize(site, source, dir, name)
|
||||||
@site = site
|
@site = site
|
||||||
@base = File.join(source, dir, subdir)
|
@base = File.join(source, dir)
|
||||||
@name = name
|
@name = name
|
||||||
|
|
||||||
self.categories = dir.split('/').reject { |x| x.empty? }
|
self.categories = dir.split('/').reject { |x| x.empty? }
|
||||||
|
|
|
@ -137,10 +137,10 @@ module Jekyll
|
||||||
base = File.join(self.source, dir)
|
base = File.join(self.source, dir)
|
||||||
entries = Dir.chdir(base) { filter_entries(Dir.entries('.')) }
|
entries = Dir.chdir(base) { filter_entries(Dir.entries('.')) }
|
||||||
|
|
||||||
self.read_posts(dir,'_posts')
|
self.read_posts(dir)
|
||||||
|
|
||||||
if self.show_drafts
|
if self.show_drafts
|
||||||
self.read_posts(dir,'_drafts')
|
self.read_drafts(dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.posts.sort!
|
self.posts.sort!
|
||||||
|
@ -174,18 +174,46 @@ module Jekyll
|
||||||
# object with each one.
|
# object with each one.
|
||||||
#
|
#
|
||||||
# dir - The String relative path of the directory to read.
|
# dir - The String relative path of the directory to read.
|
||||||
# subdir - The String relative path of the subdirectory to read.
|
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def read_posts(dir, subdir)
|
def read_posts(dir)
|
||||||
base = File.join(self.source, dir, subdir)
|
dir = File.join(dir, '_posts')
|
||||||
|
|
||||||
|
base = File.join(self.source, dir)
|
||||||
return unless File.exists?(base)
|
return unless File.exists?(base)
|
||||||
entries = Dir.chdir(base) { filter_entries(Dir['**/*']) }
|
entries = Dir.chdir(base) { filter_entries(Dir['**/*']) }
|
||||||
|
|
||||||
# first pass processes, but does not yet render post content
|
# first pass processes, but does not yet render post content
|
||||||
entries.each do |f|
|
entries.each do |f|
|
||||||
if Post.valid?(f)
|
if Post.valid?(f)
|
||||||
post = Post.new(self, self.source, dir, f, subdir)
|
post = Post.new(self, self.source, dir, f)
|
||||||
|
|
||||||
|
if post.published && (self.future || post.date <= self.time)
|
||||||
|
self.posts << post
|
||||||
|
post.categories.each { |c| self.categories[c] << post }
|
||||||
|
post.tags.each { |c| self.tags[c] << post }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Read all the files in <source>/<dir>/_drafts and create a new Post
|
||||||
|
# object with each one.
|
||||||
|
#
|
||||||
|
# dir - The String relative path of the directory to read.
|
||||||
|
#
|
||||||
|
# Returns nothing.
|
||||||
|
def read_drafts(dir)
|
||||||
|
dir = File.join(dir, '_drafts')
|
||||||
|
|
||||||
|
base = File.join(self.source, dir)
|
||||||
|
return unless File.exists?(base)
|
||||||
|
entries = Dir.chdir(base) { filter_entries(Dir['**/*']) }
|
||||||
|
|
||||||
|
# first pass processes, but does not yet render post content
|
||||||
|
entries.each do |f|
|
||||||
|
if Post.valid?(f)
|
||||||
|
post = Draft.new(self, self.source, dir, f)
|
||||||
|
|
||||||
if post.published && (self.future || post.date <= self.time)
|
if post.published && (self.future || post.date <= self.time)
|
||||||
self.posts << post
|
self.posts << post
|
||||||
|
|
Loading…
Reference in New Issue