Filter out any files/directories that are hidden or backup files (start with "." or "#" or end with "~"), or contain site content (start with "_"), or are excluded in the site configuration, unless they are web server files such as '.htaccess'.
# File 'lib/jekyll/site.rb', line 15definitialize(config)self.config=config.cloneself.safe=config['safe']self.source=File.expand_path(config['source'])self.dest=File.expand_path(config['destination'])self.plugins=Array(config['plugins']).map{|d|File.expand_path(d)}self.lsi=config['lsi']self.pygments=config['pygments']self.permalink_style=config['permalink'].to_symself.exclude=config['exclude']||[]self.include=config['include']||[]self.future=config['future']self.limit_posts=config['limit_posts']||nilself.resetself.setupend
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
6
7
8
# File 'lib/jekyll/site.rb', line 6defcategories@categoriesend
#config ⇒ Object
Returns the value of attribute config.
6
7
8
# File 'lib/jekyll/site.rb', line 6defconfig@configend
#converters ⇒ Object
Returns the value of attribute converters.
10
11
12
# File 'lib/jekyll/site.rb', line 10defconverters@convertersend
#dest ⇒ Object
Returns the value of attribute dest.
6
7
8
# File 'lib/jekyll/site.rb', line 6defdest@destend
#exclude ⇒ Object
Returns the value of attribute exclude.
6
7
8
# File 'lib/jekyll/site.rb', line 6defexclude@excludeend
#future ⇒ Object
Returns the value of attribute future.
6
7
8
# File 'lib/jekyll/site.rb', line 6deffuture@futureend
#generators ⇒ Object
Returns the value of attribute generators.
10
11
12
# File 'lib/jekyll/site.rb', line 10defgenerators@generatorsend
#include ⇒ Object
Returns the value of attribute include.
6
7
8
# File 'lib/jekyll/site.rb', line 6definclude@includeend
#layouts ⇒ Object
Returns the value of attribute layouts.
6
7
8
# File 'lib/jekyll/site.rb', line 6deflayouts@layoutsend
#limit_posts ⇒ Object
Returns the value of attribute limit_posts.
6
7
8
# File 'lib/jekyll/site.rb', line 6deflimit_posts@limit_postsend
#lsi ⇒ Object
Returns the value of attribute lsi.
6
7
8
# File 'lib/jekyll/site.rb', line 6deflsi@lsiend
#pages ⇒ Object
Returns the value of attribute pages.
6
7
8
# File 'lib/jekyll/site.rb', line 6defpages@pagesend
#permalink_style ⇒ Object
Returns the value of attribute permalink_style.
6
7
8
# File 'lib/jekyll/site.rb', line 6defpermalink_style@permalink_styleend
#plugins ⇒ Object
Returns the value of attribute plugins.
6
7
8
# File 'lib/jekyll/site.rb', line 6defplugins@pluginsend
#posts ⇒ Object
Returns the value of attribute posts.
6
7
8
# File 'lib/jekyll/site.rb', line 6defposts@postsend
#pygments ⇒ Object
Returns the value of attribute pygments.
6
7
8
# File 'lib/jekyll/site.rb', line 6defpygments@pygmentsend
#safe ⇒ Object
Returns the value of attribute safe.
6
7
8
# File 'lib/jekyll/site.rb', line 6defsafe@safeend
#source ⇒ Object
Returns the value of attribute source.
6
7
8
# File 'lib/jekyll/site.rb', line 6defsource@sourceend
#static_files ⇒ Object
Returns the value of attribute static_files.
6
7
8
# File 'lib/jekyll/site.rb', line 6defstatic_files@static_filesend
#tags ⇒ Object
Returns the value of attribute tags.
6
7
8
# File 'lib/jekyll/site.rb', line 6deftags@tagsend
#time ⇒ Object
Returns the value of attribute time.
6
7
8
# File 'lib/jekyll/site.rb', line 6deftime@timeend
Instance Method Details
#cleanup ⇒ Object
Remove orphaned files and empty directories in destination.
# File 'lib/jekyll/site.rb', line 217defcleanup# all files and directories in destination, including hidden ones
dest_files=Set.newDir.glob(File.join(self.dest,"**","*"),File::FNM_DOTMATCH)do|file|dest_files<<fileunlessfile=~/\/\.{1,2}$/end# files to be written
files=Set.newself.posts.eachdo|post|files<<post.destination(self.dest)endself.pages.eachdo|page|files<<page.destination(self.dest)endself.static_files.eachdo|sf|files<<sf.destination(self.dest)end# adding files' parent directories
dirs=Set.newfiles.each{|file|dirs<<File.dirname(file)}files.merge(dirs)obsolete_files=dest_files-filesFileUtils.rm_rf(obsolete_files.to_a)end
#filter_entries(entries) ⇒ Object
Filter out any files/directories that are hidden or backup files (start
with "." or "#" or end with "~"), or contain site content (start with "_"),
or are excluded in the site configuration, unless they are web server
files such as '.htaccess'.
entries - The Array of file/directory entries to filter.
Returns the Array of filtered entries.
314
315
316
317
318
319
320
321
322
323
# File 'lib/jekyll/site.rb', line 314deffilter_entries(entries)entries=entries.rejectdo|e|unlessself.include.include?(e)['.','_','#'].include?(e[0..0])||e[-1..-1]=='~'||self.exclude.include?(e)||File.symlink?(e)endendend
#generate ⇒ Object
Run each of the Generators.
Returns nothing.
188
189
190
191
192
# File 'lib/jekyll/site.rb', line 188defgenerateself.generators.eachdo|generator|generator.generate(self)endend
#getConverterImpl(klass) ⇒ Object
Get the implementation class for the given Converter.
klass - The Class of the Converter to fetch.
Returns the Converter instance implementing the given Converter.
330
331
332
333
334
335
336
337
# File 'lib/jekyll/site.rb', line 330defgetConverterImpl(klass)matches=self.converters.select{|c|c.class==klass}ifimpl=matches.firstimplelseraise"Converter implementation not found for #{klass}"endend
#post_attr_hash(post_attr) ⇒ Object
Constructs a Hash of Posts indexed by the specified Post attribute.
post_attr - The String name of the Post attribute.
Returns the Hash: { attr => posts } where
attr - One of the values for the requested attribute.
posts - The Array of Posts with the given attr value.
274
275
276
277
278
279
280
281
# File 'lib/jekyll/site.rb', line 274defpost_attr_hash(post_attr)# Build a hash map based on the specified post attribute ( post attr =>
# array of posts ) then sort each array in reverse order.
hash=Hash.new{|hsh,key|hsh[key]=Array.new}self.posts.each{|p|p.send(post_attr.to_sym).each{|t|hash[t]<<p}}hash.values.map{|sortme|sortme.sort!{|a,b|b<=>a}}hashend
#process ⇒ Object
Public: Read, process, and write this Site to output.
Returns nothing.
37
38
39
40
41
42
43
44
# File 'lib/jekyll/site.rb', line 37defprocessself.resetself.readself.generateself.renderself.cleanupself.writeend
#read ⇒ Object
Read Site data from disk and load it into internal data structures.
Returns nothing.
99
100
101
102
# File 'lib/jekyll/site.rb', line 99defreadself.read_layoutsself.read_directoriesend
#read_directories(dir = '') ⇒ Object
Recursively traverse directories to find posts, pages and static files
that will become part of the site according to the rules in
filter_entries.
dir - The String relative path of the directory to read.
# File 'lib/jekyll/site.rb', line 127defread_directories(dir='')base=File.join(self.source,dir)entries=Dir.chdir(base){filter_entries(Dir.entries('.'))}self.read_posts(dir)entries.eachdo|f|f_abs=File.join(base,f)f_rel=File.join(dir,f)ifFile.directory?(f_abs)nextifself.dest.sub(/\/$/,'')==f_absread_directories(f_rel)elsif!File.symlink?(f_abs)first3=File.open(f_abs){|fd|fd.read(3)}iffirst3=="---"# file appears to have a YAML header so process it as a page
pages<<Page.new(self,self.source,dir,f)else# otherwise treat it as a static file
static_files<<StaticFile.new(self,self.source,dir,f)endendendend
#read_layouts(dir = '') ⇒ Object
Read all the files in //_layouts and create a new Layout
object with each one.
Returns nothing.
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/jekyll/site.rb', line 108defread_layouts(dir='')base=File.join(self.source,dir,"_layouts")returnunlessFile.exists?(base)entries=[]Dir.chdir(base){entries=filter_entries(Dir['*.*'])}entries.eachdo|f|name=f.split(".")[0..-2].join(".")self.layouts[name]=Layout.new(self,base,f)endend
#read_posts(dir) ⇒ Object
Read all the files in //_posts and create a new Post
object with each one.
dir - The String relative path of the directory to read.
# File 'lib/jekyll/site.rb', line 158defread_posts(dir)base=File.join(self.source,dir,'_posts')returnunlessFile.exists?(base)entries=Dir.chdir(base){filter_entries(Dir['**/*'])}# first pass processes, but does not yet render post content
entries.eachdo|f|ifPost.valid?(f)post=Post.new(self,self.source,dir,f)ifpost.published&&(self.future||post.date<=self.time)self.posts<<postpost.categories.each{|c|self.categories[c]<<post}post.tags.each{|c|self.tags[c]<<post}endendendself.posts.sort!# limit the posts if :limit_posts option is set
iflimit_postslimit=self.posts.length<limit_posts?self.posts.length:limit_postsself.posts=self.posts[-limit,limit]endend
# File 'lib/jekyll/site.rb', line 197defrenderpayload=site_payloadself.posts.eachdo|post|post.render(self.layouts,payload)endself.pages.eachdo|page|page.render(self.layouts,payload)endself.categories.values.map{|ps|ps.sort!{|a,b|b<=>a}}self.tags.values.map{|ps|ps.sort!{|a,b|b<=>a}}rescueErrno::ENOENT# ignore missing layout dir
end
# File 'lib/jekyll/site.rb', line 49defresetself.time=ifself.config['time']Time.parse(self.config['time'].to_s)elseTime.nowendself.layouts={}self.posts=[]self.pages=[]self.static_files=[]self.categories=Hash.new{|hash,key|hash[key]=[]}self.tags=Hash.new{|hash,key|hash[key]=[]}if!self.limit_posts.nil?&&self.limit_posts<1raiseArgumentError,"Limit posts must be nil or >= 1"endend
#setup ⇒ Object
Load necessary libraries, plugins, converters, and generators.
# File 'lib/jekyll/site.rb', line 70defsetuprequire'classifier'ifself.lsi# If safe mode is off, load in any Ruby files under the plugins
# directory.
unlessself.safeself.plugins.eachdo|plugins|Dir[File.join(plugins,"**/*.rb")].eachdo|f|requirefendendendself.converters=Jekyll::Converter.subclasses.selectdo|c|!self.safe||c.safeend.mapdo|c|c.new(self.config)endself.generators=Jekyll::Generator.subclasses.selectdo|c|!self.safe||c.safeend.mapdo|c|c.new(self.config)endend
#site_payload ⇒ Object
The Hash payload containing site-wide data.
Returns the Hash: { "site" => data } where data is a Hash with keys:
"time" - The Time as specified in the configuration or the
current time if none was specified.
"posts" - The Array of Posts, sorted chronologically by post date
and then title.
"pages" - The Array of all Pages.
"html_pages" - The Array of HTML Pages.
"categories" - The Hash of category values and Posts.
See Site#post_attr_hash for type info.
"tags" - The Hash of tag values and Posts.
See Site#post_attr_hash for type info.
296
297
298
299
300
301
302
303
304
# File 'lib/jekyll/site.rb', line 296defsite_payload{"site"=>self.config.merge({"time"=>self.time,"posts"=>self.posts.sort{|a,b|b<=>a},"pages"=>self.pages,"html_pages"=>self.pages.reject{|page|!page.html?},"categories"=>post_attr_hash('categories'),"tags"=>post_attr_hash('tags')})}end
#write ⇒ Object
Write static files, pages, and posts.
Returns nothing.
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/jekyll/site.rb', line 249defwriteself.posts.eachdo|post|post.write(self.dest)endself.pages.eachdo|page|page.write(self.dest)endself.static_files.eachdo|sf|sf.write(self.dest)endend