commit
979d5c13c4
|
@ -138,37 +138,22 @@ module Jekyll
|
||||||
entries = Dir.chdir(base) { filter_entries(Dir.entries('.')) }
|
entries = Dir.chdir(base) { filter_entries(Dir.entries('.')) }
|
||||||
|
|
||||||
self.read_posts(dir)
|
self.read_posts(dir)
|
||||||
|
self.read_drafts(dir) if self.show_drafts
|
||||||
if self.show_drafts
|
|
||||||
self.read_drafts(dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.posts.sort!
|
self.posts.sort!
|
||||||
|
limit_posts! if limit_posts > 0 # limit the posts if :limit_posts option is set
|
||||||
# limit the posts if :limit_posts option is set
|
|
||||||
if limit_posts > 0
|
|
||||||
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)
|
||||||
f_rel = File.join(dir, f)
|
|
||||||
if File.directory?(f_abs)
|
if File.directory?(f_abs)
|
||||||
next if self.dest.sub(/\/$/, '') == f_abs
|
f_rel = File.join(dir, f)
|
||||||
read_directories(f_rel)
|
read_directories(f_rel) unless self.dest.sub(/\/$/, '') == f_abs
|
||||||
else
|
elsif has_yaml_header?(f_abs)
|
||||||
first3 = File.open(f_abs) { |fd| fd.read(3) }
|
|
||||||
if first3 == "---"
|
|
||||||
# file appears to have a YAML header so process it as a page
|
|
||||||
pages << Page.new(self, self.source, dir, f)
|
pages << Page.new(self, self.source, dir, f)
|
||||||
else
|
else
|
||||||
# otherwise treat it as a static file
|
|
||||||
static_files << StaticFile.new(self, self.source, dir, f)
|
static_files << StaticFile.new(self, self.source, dir, f)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# 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.
|
||||||
|
@ -255,15 +240,7 @@ module Jekyll
|
||||||
|
|
||||||
# files to be written
|
# files to be written
|
||||||
files = Set.new
|
files = Set.new
|
||||||
self.posts.each do |post|
|
site_files_each { |item| files << item.destination(self.dest) }
|
||||||
files << post.destination(self.dest)
|
|
||||||
end
|
|
||||||
self.pages.each do |page|
|
|
||||||
files << page.destination(self.dest)
|
|
||||||
end
|
|
||||||
self.static_files.each do |sf|
|
|
||||||
files << sf.destination(self.dest)
|
|
||||||
end
|
|
||||||
|
|
||||||
# adding files' parent directories
|
# adding files' parent directories
|
||||||
dirs = Set.new
|
dirs = Set.new
|
||||||
|
@ -294,15 +271,7 @@ module Jekyll
|
||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
def write
|
def write
|
||||||
self.posts.each do |post|
|
site_files_each { |item| item.write(self.dest) }
|
||||||
post.write(self.dest)
|
|
||||||
end
|
|
||||||
self.pages.each do |page|
|
|
||||||
page.write(self.dest)
|
|
||||||
end
|
|
||||||
self.static_files.each do |sf|
|
|
||||||
sf.write(self.dest)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Construct a Hash of Posts indexed by the specified Post attribute.
|
# Construct a Hash of Posts indexed by the specified Post attribute.
|
||||||
|
@ -434,5 +403,24 @@ module Jekyll
|
||||||
@deprecated_relative_permalinks = true
|
@deprecated_relative_permalinks = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def site_files_each
|
||||||
|
%w(posts pages static_files).each do |type|
|
||||||
|
self.send(type).each do |item|
|
||||||
|
yield item
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def has_yaml_header?(file)
|
||||||
|
"---" == File.open(file) { |fd| fd.read(3) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def limit_posts!
|
||||||
|
limit = self.posts.length < limit_posts ? self.posts.length : limit_posts
|
||||||
|
self.posts = self.posts[-limit, limit]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue