first pass at --drafts flag
This commit is contained in:
parent
065b251383
commit
0ad623fb85
|
@ -37,6 +37,7 @@ command :serve do |c|
|
||||||
|
|
||||||
c.option '-w', '--watch', 'Watch for changes and rebuild'
|
c.option '-w', '--watch', 'Watch for changes and rebuild'
|
||||||
c.option '--lsi', 'Use LSI for improved related posts'
|
c.option '--lsi', 'Use LSI for improved related posts'
|
||||||
|
c.option '--drafts', 'Render posts in the _drafts folder'
|
||||||
|
|
||||||
c.option '-p', '--port [PORT]', 'Port to listen on'
|
c.option '-p', '--port [PORT]', 'Port to listen on'
|
||||||
c.option '-h', '--host [HOST]', 'Host to bind to'
|
c.option '-h', '--host [HOST]', 'Host to bind to'
|
||||||
|
|
|
@ -30,12 +30,12 @@ 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.
|
||||||
# categories - An Array of Strings for the categories for this post.
|
# subdir - The String path to the subdirectory.
|
||||||
#
|
#
|
||||||
# Returns the new Post.
|
# Returns the new Post.
|
||||||
def initialize(site, source, dir, name)
|
def initialize(site, source, dir, name, subdir = '_posts')
|
||||||
@site = site
|
@site = site
|
||||||
@base = File.join(source, dir, '_posts')
|
@base = File.join(source, dir, subdir)
|
||||||
@name = name
|
@name = name
|
||||||
|
|
||||||
self.categories = dir.split('/').reject { |x| x.empty? }
|
self.categories = dir.split('/').reject { |x| x.empty? }
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Jekyll
|
||||||
class Site
|
class Site
|
||||||
attr_accessor :config, :layouts, :posts, :pages, :static_files,
|
attr_accessor :config, :layouts, :posts, :pages, :static_files,
|
||||||
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
|
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
|
||||||
:permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts,
|
:permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts, :show_drafts,
|
||||||
:keep_files
|
:keep_files
|
||||||
|
|
||||||
attr_accessor :converters, :generators
|
attr_accessor :converters, :generators
|
||||||
|
@ -26,6 +26,7 @@ module Jekyll
|
||||||
self.exclude = config['exclude'] || []
|
self.exclude = config['exclude'] || []
|
||||||
self.include = config['include'] || []
|
self.include = config['include'] || []
|
||||||
self.future = config['future']
|
self.future = config['future']
|
||||||
|
self.show_drafts = config['drafts'] || nil
|
||||||
self.limit_posts = config['limit_posts'] || nil
|
self.limit_posts = config['limit_posts'] || nil
|
||||||
self.keep_files = config['keep_files'] || []
|
self.keep_files = config['keep_files'] || []
|
||||||
|
|
||||||
|
@ -136,7 +137,19 @@ 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)
|
self.read_posts(dir,'_posts')
|
||||||
|
|
||||||
|
if self.show_drafts
|
||||||
|
self.read_posts(dir,'_drafts')
|
||||||
|
end
|
||||||
|
|
||||||
|
self.posts.sort!
|
||||||
|
|
||||||
|
# limit the posts if :limit_posts option is set
|
||||||
|
if limit_posts
|
||||||
|
limit = self.posts.length < limit_posts ? self.posts.length : limit_posts
|
||||||
|
self.posts = self.posts[-limit, limit]
|
||||||
|
end
|
||||||
|
|
||||||
entries.each do |f|
|
entries.each do |f|
|
||||||
f_abs = File.join(base, f)
|
f_abs = File.join(base, f)
|
||||||
|
@ -160,18 +173,19 @@ module Jekyll
|
||||||
# Read all the files in <source>/<dir>/_posts and create a new Post
|
# Read all the files in <source>/<dir>/_posts and create a new Post
|
||||||
# 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)
|
def read_posts(dir, subdir)
|
||||||
base = File.join(self.source, dir, '_posts')
|
base = File.join(self.source, dir, subdir)
|
||||||
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)
|
post = Post.new(self, self.source, dir, f, subdir)
|
||||||
|
|
||||||
if post.published && (self.future || post.date <= self.time)
|
if post.published && (self.future || post.date <= self.time)
|
||||||
self.posts << post
|
self.posts << post
|
||||||
|
@ -180,14 +194,6 @@ module Jekyll
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.posts.sort!
|
|
||||||
|
|
||||||
# limit the posts if :limit_posts option is set
|
|
||||||
if limit_posts
|
|
||||||
limit = self.posts.length < limit_posts ? self.posts.length : limit_posts
|
|
||||||
self.posts = self.posts[-limit, limit]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run each of the Generators.
|
# Run each of the Generators.
|
||||||
|
|
Loading…
Reference in New Issue