Class: JekyllOpenSdgPlugins::SiteConfiguration
- Inherits:
-
Jekyll::Generator
- Object
- Jekyll::Generator
- JekyllOpenSdgPlugins::SiteConfiguration
- Defined in:
- lib/jekyll-open-sdg-plugins/site_configuration.rb
Instance Method Summary collapse
-
#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.
-
#hash_to_hash(hash_from, hash_to) ⇒ Object
Copy properties from a hash onto another hash.
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 # Look for environment variables for some settings. env_settings = [ 'REPOSITORY_URL_SITE', ] env_settings.each do |setting| if ENV.has_key?(setting) site.config[setting.downcase] = ENV[setting] end end # Abort early if some required settings are not there. unless site.config.has_key?('languages') && site.config['languages'].length > 0 opensdg_error('The "languages" site configuration must have at least one language. See the documentation here: https://open-sdg.readthedocs.io/en/latest/configuration/#languages') end # Hardcode some variables. site.config['disaggregation_status'] = {} site.config['disaggregation_status']['status_types'] = [ { 'value' => 'complete', 'label' => 'status.disaggregation_status_complete', }, { 'value' => 'inprogress', 'label' => 'status.disaggregation_status_inprogress', }, { 'value' => 'notstarted', 'label' => 'status.disaggregation_status_notstarted', }, { 'value' => 'notapplicable', 'label' => 'status.disaggregation_status_notapplicable', }, ] # Provide some defaults. if !site.config.has_key?('time_series_attributes') or site.config['time_series_attributes'].length == 0 site.config['time_series_attributes'] = [ { 'field' => 'COMMENT_TS', 'label' => 'indicator.footnote', }, { 'field' => 'DATA_LAST_UPDATE', 'label' => 'metadata_fields.national_data_update_url' }, ] end end |
#hash_to_hash(hash_from, hash_to) ⇒ Object
Copy properties from a hash onto another hash.
86 87 88 89 90 |
# File 'lib/jekyll-open-sdg-plugins/site_configuration.rb', line 86 def hash_to_hash(hash_from, hash_to) hash_from.each do |key, value| hash_to[key] = value end end |