diff --git a/lib/jekyll/hooks.rb b/lib/jekyll/hooks.rb index 869bcc1f..6d8fcd8d 100644 --- a/lib/jekyll/hooks.rb +++ b/lib/jekyll/hooks.rb @@ -12,6 +12,7 @@ module Jekyll # initial empty hooks @registry = { :site => { + :after_init => [], :after_reset => [], :post_read => [], :pre_render => [], diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 72d42ad9..c4fe9f0c 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -17,6 +17,31 @@ module Jekyll # # config - A Hash containing site configuration details. def initialize(config) + # Source and destination may not be changed after the site has been created. + @source = File.expand_path(config['source']).freeze + @dest = File.expand_path(config['destination']).freeze + + self.config = config + + @reader = Reader.new(self) + @regenerator = Regenerator.new(self) + @liquid_renderer = LiquidRenderer.new(self) + + Jekyll.sites << self + + Jekyll::Hooks.trigger :site, :after_init, self + + reset + setup + end + + # Public: Set the site's configuration. This handles side-effects caused by + # changing values in the configuration. + # + # config - a Jekyll::Configuration, containing the new configuration. + # + # Returns the new configuration. + def config=(config) @config = config.clone %w(safe lsi highlighter baseurl exclude include future unpublished @@ -24,17 +49,6 @@ module Jekyll self.send("#{opt}=", config[opt]) end - # Source and destination may not be changed after the site has been created. - @source = File.expand_path(config['source']).freeze - @dest = File.expand_path(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 @@ -43,10 +57,7 @@ module Jekyll self.permalink_style = config['permalink'].to_sym - Jekyll.sites << self - - reset - setup + @config end # Public: Read, process, and write this Site to output. diff --git a/site/_docs/plugins.md b/site/_docs/plugins.md index 8a14fc15..8f173cb0 100644 --- a/site/_docs/plugins.md +++ b/site/_docs/plugins.md @@ -516,6 +516,18 @@ The complete list of available hooks is below:
+:site
:after_init
Just after the site initializes, but before setup & render. Good + for modifying the configuration of the site.
+:site