Class: JekyllOpenSdgPlugins::SiteConfiguration

Inherits:
Jekyll::Generator
  • Object
show all
Defined in:
lib/jekyll-open-sdg-plugins/site_configuration.rb

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object

This looks for site configuration in the data directory, and if found, copies it to the “site” object, as if it had been in _config.yml. It looks in “site_config” for configuration to move. In addition, if jekyll.environment or site.environment is specifically “production”, then it also moves data from “site_config_prod”.

This allows you to keep all OpenSDG-specific config out of _config.yml, and instead place it in site_config and/or site_config_prod in your data directory.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jekyll-open-sdg-plugins/site_configuration.rb', line 16

def generate(site)

  if site.data.has_key?('site_config')
    hash_to_hash(site.data['site_config'], site.config)
  end

  production = false
  if Jekyll.env == 'production'
    production = true
  end
  if site.config.has_key?('environment') && site.config['environment'] == 'production'
    production = true
  end

  if production && site.data.has_key?('site_config_prod')
    hash_to_hash(site.data['site_config_prod'], site.config)
  end

end

#hash_to_hash(hash_from, hash_to) ⇒ Object

Copy properties from a hash onto another hash.



37
38
39
40
41
# File 'lib/jekyll-open-sdg-plugins/site_configuration.rb', line 37

def hash_to_hash(hash_from, hash_to)
  hash_from.each do |key, value|
    hash_to[key] = value
  end
end