Class: Jekyll::Site
- Inherits:
-
Object
- Object
- Jekyll::Site
- Defined in:
- lib/jekyll/site.rb
Instance Attribute Summary collapse
-
#baseurl ⇒ Object
Returns the value of attribute baseurl.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#converters ⇒ Object
Returns the value of attribute converters.
-
#data ⇒ Object
Returns the value of attribute data.
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#drafts ⇒ Object
Returns the value of attribute drafts.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#file_read_opts ⇒ Object
Returns the value of attribute file_read_opts.
-
#future ⇒ Object
Returns the value of attribute future.
-
#gems ⇒ Object
Returns the value of attribute gems.
-
#generators ⇒ Object
Returns the value of attribute generators.
-
#highlighter ⇒ Object
Returns the value of attribute highlighter.
-
#include ⇒ Object
Returns the value of attribute include.
-
#keep_files ⇒ Object
Returns the value of attribute keep_files.
-
#layouts ⇒ Object
Returns the value of attribute layouts.
-
#limit_posts ⇒ Object
Returns the value of attribute limit_posts.
-
#liquid_renderer ⇒ Object
readonly
Returns the value of attribute liquid_renderer.
-
#lsi ⇒ Object
Returns the value of attribute lsi.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#permalink_style ⇒ Object
Returns the value of attribute permalink_style.
-
#plugin_manager ⇒ Object
Returns the value of attribute plugin_manager.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
-
#reader ⇒ Object
Returns the value of attribute reader.
-
#regenerator ⇒ Object
readonly
Returns the value of attribute regenerator.
-
#safe ⇒ Object
Returns the value of attribute safe.
-
#show_drafts ⇒ Object
Returns the value of attribute show_drafts.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#static_files ⇒ Object
Returns the value of attribute static_files.
-
#time ⇒ Object
Returns the value of attribute time.
-
#unpublished ⇒ Object
Returns the value of attribute unpublished.
Instance Method Summary collapse
- #categories ⇒ Object
-
#cleanup ⇒ Object
Remove orphaned files and empty directories in destination.
-
#collection_names ⇒ Object
The list of collection names.
-
#collections ⇒ Object
The list of collections and their corresponding Jekyll::Collection instances.
-
#docs_to_write ⇒ Object
Get the to be written documents.
-
#documents ⇒ Object
Get all the documents.
- #each_site_file ⇒ Object
-
#ensure_not_in_dest ⇒ Object
Check that the destination dir isn’t the source dir or a directory parent to the source dir.
-
#find_converter_instance(klass) ⇒ Object
Get the implementation class for the given Converter.
-
#frontmatter_defaults ⇒ Object
Returns the FrontmatterDefaults or creates a new FrontmatterDefaults if it doesn’t already exist.
-
#generate ⇒ Object
Run each of the Generators.
-
#in_dest_dir(*paths) ⇒ Object
Public: Prefix a given path with the destination directory.
-
#in_source_dir(*paths) ⇒ Object
Public: Prefix a given path with the source directory.
-
#incremental?(override = {}) ⇒ Boolean
Whether to perform a full rebuild without incremental regeneration.
-
#initialize(config) ⇒ Site
constructor
Public: Initialize a new Site.
-
#instantiate_subclasses(klass) ⇒ Object
klass - class or module containing the subclasses.
-
#post_attr_hash(post_attr) ⇒ Object
Construct a Hash of Posts indexed by the specified Post attribute.
- #posts ⇒ Object
- #print_stats ⇒ Object
-
#process ⇒ Object
Public: Read, process, and write this Site to output.
-
#publisher ⇒ Object
Returns the publisher or creates a new publisher if it doesn’t already exist.
-
#read ⇒ Object
Read Site data from disk and load it into internal data structures.
-
#relative_permalinks_are_deprecated ⇒ Object
Warns the user if permanent links are relative to the parent directory.
-
#render ⇒ Object
Render the site to the destination.
-
#reset ⇒ Object
Reset Site details.
-
#setup ⇒ Object
Load necessary libraries, plugins, converters, and generators.
-
#site_data ⇒ Object
Prepare site data for site payload.
-
#site_payload ⇒ Object
The Hash payload containing site-wide data.
- #tags ⇒ Object
-
#write ⇒ Object
Write static files, pages, and posts.
Constructor Details
#initialize(config) ⇒ Site
Public: Initialize a new Site.
config - A Hash containing site configuration details.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jekyll/site.rb', line 19 def initialize(config) @config = config.clone %w(safe lsi highlighter baseurl exclude include future unpublished show_drafts limit_posts keep_files gems).each do |opt| self.send("#{opt}=", config[opt]) end # Source and destination may not be changed after the site has been created. @source = File.(config['source']).freeze @dest = File.(config['destination']).freeze @reader = Jekyll::Reader.new(self) # Initialize incremental regenerator @regenerator = Regenerator.new(self) @liquid_renderer = LiquidRenderer.new(self) self.plugin_manager = Jekyll::PluginManager.new(self) self.plugins = plugin_manager.plugins_path self.file_read_opts = {} self.file_read_opts[:encoding] = config['encoding'] if config['encoding'] self.permalink_style = config['permalink'].to_sym Jekyll.sites << self reset setup end |
Instance Attribute Details
#baseurl ⇒ Object
Returns the value of attribute baseurl.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def baseurl @baseurl end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/jekyll/site.rb', line 6 def config @config end |
#converters ⇒ Object
Returns the value of attribute converters.
13 14 15 |
# File 'lib/jekyll/site.rb', line 13 def converters @converters end |
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def data @data end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
6 7 8 |
# File 'lib/jekyll/site.rb', line 6 def dest @dest end |
#drafts ⇒ Object
Returns the value of attribute drafts.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def drafts @drafts end |
#exclude ⇒ Object
Returns the value of attribute exclude.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def exclude @exclude end |
#file_read_opts ⇒ Object
Returns the value of attribute file_read_opts.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def file_read_opts @file_read_opts end |
#future ⇒ Object
Returns the value of attribute future.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def future @future end |
#gems ⇒ Object
Returns the value of attribute gems.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def gems @gems end |
#generators ⇒ Object
Returns the value of attribute generators.
13 14 15 |
# File 'lib/jekyll/site.rb', line 13 def generators @generators end |
#highlighter ⇒ Object
Returns the value of attribute highlighter.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def highlighter @highlighter end |
#include ⇒ Object
Returns the value of attribute include.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def include @include end |
#keep_files ⇒ Object
Returns the value of attribute keep_files.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def keep_files @keep_files end |
#layouts ⇒ Object
Returns the value of attribute layouts.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def layouts @layouts end |
#limit_posts ⇒ Object
Returns the value of attribute limit_posts.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def limit_posts @limit_posts end |
#liquid_renderer ⇒ Object (readonly)
Returns the value of attribute liquid_renderer.
14 15 16 |
# File 'lib/jekyll/site.rb', line 14 def liquid_renderer @liquid_renderer end |
#lsi ⇒ Object
Returns the value of attribute lsi.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def lsi @lsi end |
#pages ⇒ Object
Returns the value of attribute pages.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def pages @pages end |
#permalink_style ⇒ Object
Returns the value of attribute permalink_style.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def permalink_style @permalink_style end |
#plugin_manager ⇒ Object
Returns the value of attribute plugin_manager.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def plugin_manager @plugin_manager end |
#plugins ⇒ Object
Returns the value of attribute plugins.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def plugins @plugins end |
#reader ⇒ Object
Returns the value of attribute reader.
13 14 15 |
# File 'lib/jekyll/site.rb', line 13 def reader @reader end |
#regenerator ⇒ Object (readonly)
Returns the value of attribute regenerator.
14 15 16 |
# File 'lib/jekyll/site.rb', line 14 def regenerator @regenerator end |
#safe ⇒ Object
Returns the value of attribute safe.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def safe @safe end |
#show_drafts ⇒ Object
Returns the value of attribute show_drafts.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def show_drafts @show_drafts end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/jekyll/site.rb', line 6 def source @source end |
#static_files ⇒ Object
Returns the value of attribute static_files.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def static_files @static_files end |
#time ⇒ Object
Returns the value of attribute time.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def time @time end |
#unpublished ⇒ Object
Returns the value of attribute unpublished.
7 8 9 |
# File 'lib/jekyll/site.rb', line 7 def unpublished @unpublished end |
Instance Method Details
#categories ⇒ Object
237 238 239 |
# File 'lib/jekyll/site.rb', line 237 def categories post_attr_hash('categories') end |
#cleanup ⇒ Object
Remove orphaned files and empty directories in destination.
Returns nothing.
192 193 194 |
# File 'lib/jekyll/site.rb', line 192 def cleanup site_cleaner.cleanup! end |
#collection_names ⇒ Object
The list of collection names.
Returns an array of collection names from the configuration,
or an empty array if the `collections` key is not set.
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/jekyll/site.rb', line 127 def collection_names case config['collections'] when Hash config['collections'].keys when Array config['collections'] when nil [] else raise ArgumentError, "Your `collections` key must be a hash or an array." end end |
#collections ⇒ Object
119 120 121 |
# File 'lib/jekyll/site.rb', line 119 def collections @collections ||= Hash[collection_names.map { |coll| [coll, Jekyll::Collection.new(self, coll)] } ] end |
#docs_to_write ⇒ Object
Get the to be written documents
Returns an Array of Documents which should be written
303 304 305 |
# File 'lib/jekyll/site.rb', line 303 def docs_to_write documents.select(&:write?) end |
#documents ⇒ Object
Get all the documents
Returns an Array of all Documents
310 311 312 313 314 |
# File 'lib/jekyll/site.rb', line 310 def documents collections.reduce(Set.new) do |docs, (_, collection)| docs + collection.docs + collection.files end.to_a end |
#each_site_file ⇒ Object
316 317 318 319 320 321 322 |
# File 'lib/jekyll/site.rb', line 316 def each_site_file %w(pages static_files docs_to_write).each do |type| send(type).each do |item| yield item end end end |
#ensure_not_in_dest ⇒ Object
Check that the destination dir isn’t the source dir or a directory parent to the source dir.
105 106 107 108 109 110 111 112 |
# File 'lib/jekyll/site.rb', line 105 def ensure_not_in_dest dest_pathname = Pathname.new(dest) Pathname.new(source).ascend do |path| if path == dest_pathname raise Errors::FatalException.new "Destination directory cannot be or contain the Source directory." end end end |
#find_converter_instance(klass) ⇒ Object
Get the implementation class for the given Converter. Returns the Converter instance implementing the given Converter. klass - The Class of the Converter to fetch.
270 271 272 273 |
# File 'lib/jekyll/site.rb', line 270 def find_converter_instance(klass) converters.find { |klass_| klass_.instance_of?(klass) } || \ raise("No Converters found for #{klass}") end |
#frontmatter_defaults ⇒ Object
Returns the FrontmatterDefaults or creates a new FrontmatterDefaults if it doesn’t already exist.
Returns The FrontmatterDefaults
328 329 330 |
# File 'lib/jekyll/site.rb', line 328 def frontmatter_defaults @frontmatter_defaults ||= FrontmatterDefaults.new(self) end |
#generate ⇒ Object
Run each of the Generators.
Returns nothing.
152 153 154 155 156 |
# File 'lib/jekyll/site.rb', line 152 def generate generators.each do |generator| generator.generate(self) end end |
#in_dest_dir(*paths) ⇒ Object
Public: Prefix a given path with the destination directory.
paths - (optional) path elements to a file or directory within the
destination directory
Returns a path which is prefixed with the destination directory.
365 366 367 368 369 |
# File 'lib/jekyll/site.rb', line 365 def in_dest_dir(*paths) paths.reduce(dest) do |base, path| Jekyll.sanitized_path(base, path) end end |
#in_source_dir(*paths) ⇒ Object
Public: Prefix a given path with the source directory.
paths - (optional) path elements to a file or directory within the
source directory
Returns a path which is prefixed with the source directory.
353 354 355 356 357 |
# File 'lib/jekyll/site.rb', line 353 def in_source_dir(*paths) paths.reduce(source) do |base, path| Jekyll.sanitized_path(base, path) end end |
#incremental?(override = {}) ⇒ Boolean
Whether to perform a full rebuild without incremental regeneration
Returns a Boolean: true for a full rebuild, false for normal build
335 336 337 |
# File 'lib/jekyll/site.rb', line 335 def incremental?(override = {}) override['incremental'] || config['incremental'] end |
#instantiate_subclasses(klass) ⇒ Object
klass - class or module containing the subclasses. Returns array of instances of subclasses of parameter. Create array of instances of the subclasses of the class or module passed in as argument.
280 281 282 283 284 |
# File 'lib/jekyll/site.rb', line 280 def instantiate_subclasses(klass) klass.descendants.select { |c| !safe || c.safe }.sort.map do |c| c.new(config) end end |
#post_attr_hash(post_attr) ⇒ Object
Construct a Hash of Posts indexed by the specified Post attribute.
post_attr - The String name of the Post attribute.
Examples
post_attr_hash('categories')
# => { 'tech' => [<Post A>, <Post B>],
# 'ruby' => [<Post B>] }
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.
224 225 226 227 228 229 230 231 |
# File 'lib/jekyll/site.rb', line 224 def post_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 { |h, key| h[key] = [] } posts.docs.each { |p| p.data[post_attr].each { |t| hash[t] << p } if p.data[post_attr] } hash.values.each { |posts| posts.sort!.reverse! } hash end |
#posts ⇒ Object
207 208 209 |
# File 'lib/jekyll/site.rb', line 207 def posts collections['posts'] ||= Collection.new(self, 'posts') end |
#print_stats ⇒ Object
65 66 67 68 69 |
# File 'lib/jekyll/site.rb', line 65 def print_stats if @config['profile'] puts @liquid_renderer.stats_table end end |
#process ⇒ Object
Public: Read, process, and write this Site to output.
Returns nothing.
55 56 57 58 59 60 61 62 63 |
# File 'lib/jekyll/site.rb', line 55 def process reset read generate render cleanup write print_stats end |
#publisher ⇒ Object
Returns the publisher or creates a new publisher if it doesn’t already exist.
Returns The Publisher
343 344 345 |
# File 'lib/jekyll/site.rb', line 343 def publisher @publisher ||= Publisher.new(self) end |
#read ⇒ Object
Read Site data from disk and load it into internal data structures.
Returns nothing.
143 144 145 146 147 |
# File 'lib/jekyll/site.rb', line 143 def read reader.read limit_posts! Jekyll::Hooks.trigger :site, :post_read, self end |
#relative_permalinks_are_deprecated ⇒ Object
Warns the user if permanent links are relative to the parent directory. As this is a deprecated function of Jekyll.
Returns
290 291 292 293 294 295 296 297 298 |
# File 'lib/jekyll/site.rb', line 290 def relative_permalinks_are_deprecated if config['relative_permalinks'] Jekyll.logger.abort_with "Since v3.0, permalinks for pages" \ " in subfolders must be relative to the" \ " site source directory, not the parent" \ " directory. Check http://jekyllrb.com/docs/upgrading/"\ " for more info." end end |
#render ⇒ Object
Render the site to the destination.
Returns nothing.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/jekyll/site.rb', line 161 def render relative_permalinks_are_deprecated payload = site_payload Jekyll::Hooks.trigger :site, :pre_render, self, payload collections.each do |_, collection| collection.docs.each do |document| if regenerator.regenerate?(document) document.output = Jekyll::Renderer.new(self, document, payload).run document.trigger_hooks(:post_render) end end end pages.flatten.each do |page| if regenerator.regenerate?(page) page.output = Jekyll::Renderer.new(self, page, payload).run page.trigger_hooks(:post_render) end end Jekyll::Hooks.trigger :site, :post_render, self, payload rescue Errno::ENOENT # ignore missing layout dir end |
#reset ⇒ Object
Reset Site details.
Returns nothing
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jekyll/site.rb', line 74 def reset self.time = (config['time'] ? Utils.parse_date(config['time'].to_s, "Invalid time in _config.yml.") : Time.now) self.layouts = {} self.pages = [] self.static_files = [] self.data = {} @collections = nil @regenerator.clear_cache @liquid_renderer.reset if limit_posts < 0 raise ArgumentError, "limit_posts must be a non-negative number" end Jekyll::Hooks.trigger :site, :after_reset, self end |
#setup ⇒ Object
Load necessary libraries, plugins, converters, and generators.
Returns nothing.
94 95 96 97 98 99 100 101 |
# File 'lib/jekyll/site.rb', line 94 def setup ensure_not_in_dest plugin_manager.conscientious_require self.converters = instantiate_subclasses(Jekyll::Converter) self.generators = instantiate_subclasses(Jekyll::Generator) end |
#site_data ⇒ Object
Prepare site data for site payload. The method maintains backward compatibility if the key ‘data’ is already used in _config.yml.
Returns the Hash to be hooked to site.data.
245 246 247 |
# File 'lib/jekyll/site.rb', line 245 def site_data config['data'] || data end |
#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.
262 263 264 |
# File 'lib/jekyll/site.rb', line 262 def site_payload Drops::UnifiedPayloadDrop.new self end |
#tags ⇒ Object
233 234 235 |
# File 'lib/jekyll/site.rb', line 233 def post_attr_hash('tags') end |