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'.
Initialize the site
config is a Hash containing site configurations details
Returns
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jekyll/site.rb', line 11definitialize(config)self.config=config.cloneself.source=File.expand_path(config['source'])self.dest=config['destination']self.lsi=config['lsi']self.pygments=config['pygments']self.permalink_style=config['permalink'].to_symself.exclude=config['exclude']||[]self.resetself.setupend
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
4
5
6
# File 'lib/jekyll/site.rb', line 4defcategories@categoriesend
#config ⇒ Object
Returns the value of attribute config.
4
5
6
# File 'lib/jekyll/site.rb', line 4defconfig@configend
#dest ⇒ Object
Returns the value of attribute dest.
4
5
6
# File 'lib/jekyll/site.rb', line 4defdest@destend
#exclude ⇒ Object
Returns the value of attribute exclude.
4
5
6
# File 'lib/jekyll/site.rb', line 4defexclude@excludeend
#layouts ⇒ Object
Returns the value of attribute layouts.
4
5
6
# File 'lib/jekyll/site.rb', line 4deflayouts@layoutsend
#lsi ⇒ Object
Returns the value of attribute lsi.
4
5
6
# File 'lib/jekyll/site.rb', line 4deflsi@lsiend
#pages ⇒ Object
Returns the value of attribute pages.
4
5
6
# File 'lib/jekyll/site.rb', line 4defpages@pagesend
#permalink_style ⇒ Object
Returns the value of attribute permalink_style.
4
5
6
# File 'lib/jekyll/site.rb', line 4defpermalink_style@permalink_styleend
#posts ⇒ Object
Returns the value of attribute posts.
4
5
6
# File 'lib/jekyll/site.rb', line 4defposts@postsend
#pygments ⇒ Object
Returns the value of attribute pygments.
4
5
6
# File 'lib/jekyll/site.rb', line 4defpygments@pygmentsend
#source ⇒ Object
Returns the value of attribute source.
4
5
6
# File 'lib/jekyll/site.rb', line 4defsource@sourceend
#static_files ⇒ Object
Returns the value of attribute static_files.
4
5
6
# File 'lib/jekyll/site.rb', line 4defstatic_files@static_filesend
#tags ⇒ Object
Returns the value of attribute tags.
4
5
6
# File 'lib/jekyll/site.rb', line 4deftags@tagsend
Instance Method Details
#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'
243
244
245
246
247
248
249
# File 'lib/jekyll/site.rb', line 243deffilter_entries(entries)entries=entries.rejectdo|e|unless['.htaccess'].include?(e)['.','_','#'].include?(e[0..0])||e[-1..-1]=='~'||self.exclude.include?(e)endendend
#paginate(page) ⇒ Object
Paginates the blog's posts. Renders the index.html file into paginated
directories, ie: page2/index.html, page3/index.html, etc and adds more
site-wide data.
page is the index.html Page that requires pagination
# File 'lib/jekyll/site.rb', line 263defpaginate(page)all_posts=site_payload['site']['posts']pages=Pager.calculate_pages(all_posts,self.config['paginate'].to_i)(1..pages).eachdo|num_page|pager=Pager.new(self.config,num_page,all_posts,pages)ifnum_page>1newpage=Page.new(self,self.source,page.dir,page.name)newpage.render(self.layouts,site_payload.merge({'paginator'=>pager.to_hash}))newpage.dir=File.join(page.dir,"page#{num_page}")newpage.basename='index.html'self.pages<<newpageelsepage.render(self.layouts,site_payload.merge({'paginator'=>pager.to_hash}))endendend
#post_attr_hash(post_attr) ⇒ Object
Constructs a hash map of Posts indexed by the specified Post attribute
Returns => []
217
218
219
220
221
222
223
224
# File 'lib/jekyll/site.rb', line 217defpost_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{|hash,key|hash[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}}returnhashend
#process ⇒ Object
Do the actual work of processing the site and generating the
real deal. Now has 4 phases; reset, read, render, write. This allows
rendering to have full site payload available.
Returns nothing
96
97
98
99
100
101
# File 'lib/jekyll/site.rb', line 96defprocessself.resetself.readself.renderself.writeend
#read ⇒ Object
103
104
105
106
# File 'lib/jekyll/site.rb', line 103defreadself.read_layouts# existing implementation did this at top level only so preserved that
self.read_directoriesend
#read_directories(dir = '') ⇒ Object
Reads the directories and finds posts, pages and static files that will
become part of the valid site according to the rules in filter_entries.
The dir String is a relative path used to call this method
recursively as it descends through directories
# File 'lib/jekyll/site.rb', line 189defread_directories(dir='')base=File.join(self.source,dir)entries=filter_entries(Dir.entries(base))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
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/jekyll/site.rb', line 112defread_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.
# File 'lib/jekyll/site.rb', line 128defread_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.publishedself.posts<<postpost.categories.each{|c|self.categories[c]<<post}post.tags.each{|c|self.tags[c]<<post}endendendself.posts.sort!end
# File 'lib/jekyll/site.rb', line 149defrenderself.posts.eachdo|post|post.render(self.layouts,site_payload)endself.pages.dup.eachdo|page|ifPager.pagination_enabled?(self.config,page.name)paginate(page)elsepage.render(self.layouts,site_payload)endendself.categories.values.map{|ps|ps.sort!{|a,b|b<=>a}}self.tags.values.map{|ps|ps.sort!{|a,b|b<=>a}}rescueErrno::ENOENT=>e# ignore missing layout dir
end
#reset ⇒ Object
25
26
27
28
29
30
31
32
# File 'lib/jekyll/site.rb', line 25defresetself.layouts={}self.posts=[]self.pages=[]self.static_files=[]self.categories=Hash.new{|hash,key|hash[key]=[]}self.tags=Hash.new{|hash,key|hash[key]=[]}end
# File 'lib/jekyll/site.rb', line 34defsetup# Check to see if LSI is enabled.
require'classifier'ifself.lsi# Set the Markdown interpreter (and Maruku self.config, if necessary)
caseself.config['markdown']when'rdiscount'beginrequire'rdiscount'defmarkdown(content)RDiscount.new(content).to_htmlendrescueLoadErrorputs'You must have the rdiscount gem installed first'endwhen'maruku'beginrequire'maruku'defmarkdown(content)Maruku.new(content).to_htmlendifself.config['maruku']['use_divs']require'maruku/ext/div'puts'Maruku: Using extended syntax for div elements.'endifself.config['maruku']['use_tex']require'maruku/ext/math'puts"Maruku: Using LaTeX extension. Images in `#{self.config['maruku']['png_dir']}`."# Switch off MathML output
MaRuKu::Globals[:html_math_output_mathml]=falseMaRuKu::Globals[:html_math_engine]='none'# Turn on math to PNG support with blahtex
# Resulting PNGs stored in `images/latex`
MaRuKu::Globals[:html_math_output_png]=trueMaRuKu::Globals[:html_png_engine]=self.config['maruku']['png_engine']MaRuKu::Globals[:html_png_dir]=self.config['maruku']['png_dir']MaRuKu::Globals[:html_png_url]=self.config['maruku']['png_url']endrescueLoadErrorputs"The maruku gem is required for markdown support!"endelseraise"Invalid Markdown processor: '#{self.config['markdown']}' -- did you mean 'maruku' or 'rdiscount'?"endend
#site_payload ⇒ Object
The Hash payload containing site-wide data
Returns => {"time" =>
231
232
233
234
235
236
237
# File 'lib/jekyll/site.rb', line 231defsite_payload{"site"=>self.config.merge({"time"=>Time.now,"posts"=>self.posts.sort{|a,b|b<=>a},"categories"=>post_attr_hash('categories'),"tags"=>post_attr_hash('tags')})}end
#textile(content) ⇒ Object
87
88
89
# File 'lib/jekyll/site.rb', line 87deftextile(content)RedCloth.new(content).to_htmlend
#write ⇒ Object
Write static files, pages and posts
Returns nothing
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/jekyll/site.rb', line 171defwriteself.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