From 84b7d9b3ac6e1218dc910d32dd423bf922bfaff4 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 23 Mar 2016 13:14:08 -0700 Subject: [PATCH 1/2] Add Hook for :site :after_init --- lib/jekyll/hooks.rb | 1 + lib/jekyll/site.rb | 18 +++--------------- site/_docs/plugins.md | 12 ++++++++++++ 3 files changed, 16 insertions(+), 15 deletions(-) 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..7f76e981 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -17,6 +17,8 @@ module Jekyll # # config - A Hash containing site configuration details. def initialize(config) + + Jekyll::Hooks.trigger :site, :after_init, self @config = config.clone %w(safe lsi highlighter baseurl exclude include future unpublished @@ -24,17 +26,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 +34,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

From 9b60df88831073f6a8a760684bf65bf1d87d0fb4 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 23 Mar 2016 13:14:30 -0700 Subject: [PATCH 2/2] Add Site#config= which can be used to set the config --- lib/jekyll/site.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 7f76e981..c4fe9f0c 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -17,8 +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