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
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jekyll/site.rb', line 14definitialize(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.post_defaults=config['post_defaults']||{}self.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
#collated_posts ⇒ Object
Returns the value of attribute collated_posts.
7
8
9
# File 'lib/jekyll/site.rb', line 7defcollated_posts@collated_postsend
#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
#post_defaults ⇒ Object
Returns the value of attribute post_defaults.
7
8
9
# File 'lib/jekyll/site.rb', line 7defpost_defaults@post_defaultsend
#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
#sass ⇒ Object
Returns the value of attribute sass.
7
8
9
# File 'lib/jekyll/site.rb', line 7defsass@sassend
#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'
294
295
296
297
298
299
300
# File 'lib/jekyll/site.rb', line 294deffilter_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 314defpaginate(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}")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 => []
268
269
270
271
272
273
274
275
# File 'lib/jekyll/site.rb', line 268defpost_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 orderhash=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
123
124
125
126
127
128
129
# File 'lib/jekyll/site.rb', line 123defprocessself.resetself.readself.renderself.writeself.transform_sassifself.sassend
#read ⇒ Object
131
132
133
134
# File 'lib/jekyll/site.rb', line 131defreadself.read_layouts# existing implementation did this at top level only so preserved thatself.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 218defread_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 pagepages<<Page.new(self,self.source,dir,f)else# otherwise treat it as a static filestatic_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
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/jekyll/site.rb', line 140defread_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 156defread_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 contententries.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 177defrenderself.posts.eachdo|post|post.render(self.layouts,site_payload)self.collated_posts[post.date.year][post.date.month][post.date.day].unshift(post)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 dirend
#reset ⇒ Object
29
30
31
32
33
34
35
36
37
# File 'lib/jekyll/site.rb', line 29defresetself.layouts={}self.posts=[]self.collated_posts=Hash.new{|h,k|h[k]=Hash.new{|h,k|h[k]=Hash.new{|h,k|h[k]=[]}}}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 39defsetup# Check to see if LSI is enabled.require'classifier'ifself.lsiifself.config['sass']beginrequire'sass'self.sass=trueputs'Using Sass for CSS generation'rescueLoadErrorputs'You must have the haml gem installed first'endendifself.config['haml']beginrequire'haml'require'jekyll/haml_helpers'helpers=File.join(source,'_helpers.rb')requirehelpersifFile.exist?(helpers)puts'Enabled Haml'rescueLoadErrorputs'You must have the haml gem installed first'endend# 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 outputMaRuKu::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" =>
282
283
284
285
286
287
288
# File 'lib/jekyll/site.rb', line 282defsite_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
114
115
116
# File 'lib/jekyll/site.rb', line 114deftextile(content)RedCloth.new(content).to_htmlend
#transform_sass(dir = '') ⇒ Object
Transform all *.sass files from to css with the same name
and delete source sass files.
Returns nothing
# File 'lib/jekyll/site.rb', line 246deftransform_sass(dir='')base=File.join(self.source,dir)entries=Dir.entries(base)entries=entries.reject{|e|['.','_'].include?(e[0..0])}directories=entries.select{|e|File.directory?(File.join(base,e))}directories.each{|d|transform_sass(File.join(dir,d))}files=entries.reject{|e|File.directory?(File.join(base,e))}files=files.select{|f|File.extname(File.join(base,f))==".sass"}files.eachdo|f|input=File.open(File.join(base,f),"r")result=Sass::Engine.new(input.read,:style=>:compact,:load_paths=>base).renderFileUtils.mkdir_p(File.join(self.dest,dir))output=File.open(File.join(self.dest,dir,f).gsub(/.sass\Z/,".css"),"w")do|o|o.write(result)endFileUtils.rm(File.join(self.dest,dir,f))endend
#write ⇒ Object
Write static files, pages and posts
Returns nothing
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/jekyll/site.rb', line 200defwriteself.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