jekyll-open-sdg-plugins 1.6.1 → 1.8.0.pre.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +16 -16
- data/.github/workflows/test-pull-requests.yml +17 -17
- data/.gitignore +6 -6
- data/LICENSE +21 -21
- data/Makefile +33 -33
- data/README.md +7 -7
- data/jekyll-open-sdg-plugins.gemspec +18 -18
- data/lib/jekyll-open-sdg-plugins/backwards_compatibility.rb +97 -64
- data/lib/jekyll-open-sdg-plugins/create_goals.rb +88 -85
- data/lib/jekyll-open-sdg-plugins/create_indicators.rb +209 -206
- data/lib/jekyll-open-sdg-plugins/create_pages.rb +150 -135
- data/lib/jekyll-open-sdg-plugins/fetch_remote_data.rb +188 -188
- data/lib/jekyll-open-sdg-plugins/helpers.rb +132 -132
- data/lib/jekyll-open-sdg-plugins/metadata_schema_to_config.rb +72 -72
- data/lib/jekyll-open-sdg-plugins/schema-indicator-config.json +787 -709
- data/lib/jekyll-open-sdg-plugins/schema-site-config.json +1712 -1607
- data/lib/jekyll-open-sdg-plugins/sdg_variables.rb +614 -549
- data/lib/jekyll-open-sdg-plugins/search_index.rb +102 -102
- data/lib/jekyll-open-sdg-plugins/site_configuration.rb +87 -73
- data/lib/jekyll-open-sdg-plugins/translate_date.rb +122 -122
- data/lib/jekyll-open-sdg-plugins/translate_key.rb +20 -20
- data/lib/jekyll-open-sdg-plugins/translate_metadata_field.rb +111 -111
- data/lib/jekyll-open-sdg-plugins/validate_indicator_config.rb +52 -52
- data/lib/jekyll-open-sdg-plugins/validate_site_config.rb +34 -34
- data/lib/jekyll-open-sdg-plugins/version.rb +3 -3
- data/lib/jekyll-open-sdg-plugins.rb +18 -18
- data/tests/Gemfile +7 -7
- data/tests/_config.yml +168 -168
- metadata +5 -5
@@ -1,206 +1,209 @@
|
|
1
|
-
require "jekyll"
|
2
|
-
require_relative "helpers"
|
3
|
-
|
4
|
-
module JekyllOpenSdgPlugins
|
5
|
-
class CreateIndicators < Jekyll::Generator
|
6
|
-
safe true
|
7
|
-
priority :normal
|
8
|
-
|
9
|
-
def generate(site)
|
10
|
-
# Some references to clean up the code below.
|
11
|
-
language_config = site.config['languages']
|
12
|
-
indicator_config = site.config['create_indicators']
|
13
|
-
form_settings_config = site.config['indicator_config_form']
|
14
|
-
form_settings_meta = site.config['indicator_metadata_form']
|
15
|
-
form_settings_data = site.config['indicator_data_form']
|
16
|
-
|
17
|
-
translations = site.data['translations']
|
18
|
-
# If site.create_indicators is set, create indicators per the metadata.
|
19
|
-
if (language_config and indicator_config and indicator_config.key?('layout') and indicator_config['layout'] != '')
|
20
|
-
# Decide what layout to use for the indicator pages.
|
21
|
-
layout = indicator_config['layout']
|
22
|
-
# See if we need to "map" any language codes.
|
23
|
-
languages_public = Hash.new
|
24
|
-
if site.config['languages_public']
|
25
|
-
languages_public = opensdg_languages_public(site)
|
26
|
-
end
|
27
|
-
# Loop through the languages.
|
28
|
-
language_config.each_with_index do |language, index|
|
29
|
-
# Get the "public language" (for URLs) which may be different.
|
30
|
-
language_public = language
|
31
|
-
if languages_public[language]
|
32
|
-
language_public = languages_public[language]
|
33
|
-
end
|
34
|
-
metadata = {}
|
35
|
-
if opensdg_translated_builds(site)
|
36
|
-
# If we are using translated builds, the metadata is underneath a
|
37
|
-
# language code.
|
38
|
-
metadata = site.data[language]['meta']
|
39
|
-
else
|
40
|
-
# Otherwise the 'meta' data is not underneath any language code.
|
41
|
-
metadata = site.data['meta']
|
42
|
-
end
|
43
|
-
# Loop through the indicators (using metadata as a list).
|
44
|
-
metadata.each do |inid, meta|
|
45
|
-
permalink = inid
|
46
|
-
if (meta.has_key?('permalink') and meta['permalink'] != '')
|
47
|
-
permalink = meta['permalink']
|
48
|
-
end
|
49
|
-
# Add the language subfolder for all except the default (first) language.
|
50
|
-
dir = index == 0 ? permalink : File.join(language_public, permalink)
|
51
|
-
|
52
|
-
# Create the indicator page.
|
53
|
-
site.collections['indicators'].docs << IndicatorPage.new(site, site.source, dir, inid, language, layout)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
# Create the indicator settings configuration/metadata/data pages.
|
57
|
-
do_indicator_config_forms = form_settings_config && form_settings_config['enabled']
|
58
|
-
do_indicator_meta_forms = form_settings_meta && form_settings_meta['enabled']
|
59
|
-
do_indicator_data_forms = form_settings_data && form_settings_data['enabled']
|
60
|
-
use_translated_metadata = form_settings_meta && form_settings_meta['translated']
|
61
|
-
if do_indicator_config_forms || do_indicator_meta_forms || do_indicator_data_forms
|
62
|
-
|
63
|
-
metadata = {}
|
64
|
-
if opensdg_translated_builds(site)
|
65
|
-
if site.data.has_key?('untranslated')
|
66
|
-
metadata = site.data['untranslated']['meta']
|
67
|
-
else
|
68
|
-
default_language = language_config[0]
|
69
|
-
metadata = site.data[default_language]['meta']
|
70
|
-
end
|
71
|
-
else
|
72
|
-
metadata = site.data['meta']
|
73
|
-
end
|
74
|
-
|
75
|
-
metadata_by_language = {}
|
76
|
-
language_config.each do |language|
|
77
|
-
if opensdg_translated_builds(site)
|
78
|
-
metadata_by_language[language] = site.data[language]['meta']
|
79
|
-
else
|
80
|
-
metadata_by_language[language] = site.data['meta']
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# Because we have config forms for indicator config or meta/data, we
|
85
|
-
# take over the meta/data_edit_url and configuration_edit_url settings
|
86
|
-
# here with simple relative links.
|
87
|
-
if do_indicator_config_forms
|
88
|
-
site.config['configuration_edit_url'] = 'config'
|
89
|
-
end
|
90
|
-
|
91
|
-
if do_indicator_meta_forms
|
92
|
-
site.config['metadata_edit_url'] = 'metadata'
|
93
|
-
end
|
94
|
-
|
95
|
-
if do_indicator_data_forms
|
96
|
-
site.config['data_edit_url'] = 'data'
|
97
|
-
end
|
98
|
-
|
99
|
-
# Loop through the indicators (using metadata as a list).
|
100
|
-
if !metadata.empty?
|
101
|
-
# Loop through the languages.
|
102
|
-
language_config.each_with_index do |language, index|
|
103
|
-
# Get the "public language" (for URLs) which may be different.
|
104
|
-
language_public = language
|
105
|
-
if languages_public[language]
|
106
|
-
language_public = languages_public[language]
|
107
|
-
end
|
108
|
-
metadata.each do |inid, meta|
|
109
|
-
permalink = inid
|
110
|
-
if (meta.has_key?('permalink') and meta['permalink'] != '')
|
111
|
-
permalink = meta['permalink']
|
112
|
-
end
|
113
|
-
dir_base = File.join(permalink)
|
114
|
-
if index != 0
|
115
|
-
dir_base = File.join(language_public, permalink)
|
116
|
-
end
|
117
|
-
|
118
|
-
if do_indicator_config_forms
|
119
|
-
dir = File.join(dir_base, 'config')
|
120
|
-
title = opensdg_translate_key('indicator.edit_configuration', translations, language)
|
121
|
-
config_type = 'indicator'
|
122
|
-
site.collections['pages'].docs << IndicatorConfigPage.new(site, site.source, dir, inid, language, meta, title, config_type, form_settings_config)
|
123
|
-
end
|
124
|
-
|
125
|
-
if do_indicator_meta_forms
|
126
|
-
metadata_to_use = meta
|
127
|
-
if use_translated_metadata
|
128
|
-
metadata_to_use = metadata_by_language[language][inid]
|
129
|
-
end
|
130
|
-
dir = File.join(dir_base, 'metadata')
|
131
|
-
title = opensdg_translate_key('indicator.edit_metadata', translations, language)
|
132
|
-
config_type = 'metadata'
|
133
|
-
site.collections['pages'].docs << IndicatorConfigPage.new(site, site.source, dir, inid, language, metadata_to_use, title, config_type, form_settings_meta)
|
134
|
-
end
|
135
|
-
|
136
|
-
if do_indicator_data_forms
|
137
|
-
dir = File.join(dir_base, 'data')
|
138
|
-
title = opensdg_translate_key('indicator.edit_data', translations, language)
|
139
|
-
site.collections['pages'].docs << IndicatorDataPage.new(site, site.source, dir, inid, language, title, form_settings_data)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# A Page subclass used in the `CreateIndicators` class for the indicators.
|
150
|
-
class IndicatorPage < Jekyll::Page
|
151
|
-
def initialize(site, base, dir, inid, language, layout)
|
152
|
-
@site = site
|
153
|
-
@base = base
|
154
|
-
@dir = dir
|
155
|
-
@name = 'index.html'
|
156
|
-
|
157
|
-
self.process(@name)
|
158
|
-
self.data = {}
|
159
|
-
self.data['indicator_number'] = inid.gsub('-', '.')
|
160
|
-
self.data['layout'] = layout
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
@
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
self.
|
179
|
-
self.data
|
180
|
-
self.data['
|
181
|
-
self.data['
|
182
|
-
self.data['
|
183
|
-
self.data['
|
184
|
-
self.data['
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
@
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
self.
|
200
|
-
self.data
|
201
|
-
self.data['
|
202
|
-
self.data['
|
203
|
-
self.data['
|
204
|
-
|
205
|
-
|
206
|
-
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "helpers"
|
3
|
+
|
4
|
+
module JekyllOpenSdgPlugins
|
5
|
+
class CreateIndicators < Jekyll::Generator
|
6
|
+
safe true
|
7
|
+
priority :normal
|
8
|
+
|
9
|
+
def generate(site)
|
10
|
+
# Some references to clean up the code below.
|
11
|
+
language_config = site.config['languages']
|
12
|
+
indicator_config = site.config['create_indicators']
|
13
|
+
form_settings_config = site.config['indicator_config_form']
|
14
|
+
form_settings_meta = site.config['indicator_metadata_form']
|
15
|
+
form_settings_data = site.config['indicator_data_form']
|
16
|
+
|
17
|
+
translations = site.data['translations']
|
18
|
+
# If site.create_indicators is set, create indicators per the metadata.
|
19
|
+
if (language_config and indicator_config and indicator_config.key?('layout') and indicator_config['layout'] != '')
|
20
|
+
# Decide what layout to use for the indicator pages.
|
21
|
+
layout = indicator_config['layout']
|
22
|
+
# See if we need to "map" any language codes.
|
23
|
+
languages_public = Hash.new
|
24
|
+
if site.config['languages_public']
|
25
|
+
languages_public = opensdg_languages_public(site)
|
26
|
+
end
|
27
|
+
# Loop through the languages.
|
28
|
+
language_config.each_with_index do |language, index|
|
29
|
+
# Get the "public language" (for URLs) which may be different.
|
30
|
+
language_public = language
|
31
|
+
if languages_public[language]
|
32
|
+
language_public = languages_public[language]
|
33
|
+
end
|
34
|
+
metadata = {}
|
35
|
+
if opensdg_translated_builds(site)
|
36
|
+
# If we are using translated builds, the metadata is underneath a
|
37
|
+
# language code.
|
38
|
+
metadata = site.data[language]['meta']
|
39
|
+
else
|
40
|
+
# Otherwise the 'meta' data is not underneath any language code.
|
41
|
+
metadata = site.data['meta']
|
42
|
+
end
|
43
|
+
# Loop through the indicators (using metadata as a list).
|
44
|
+
metadata.each do |inid, meta|
|
45
|
+
permalink = inid
|
46
|
+
if (meta.has_key?('permalink') and meta['permalink'] != '')
|
47
|
+
permalink = meta['permalink']
|
48
|
+
end
|
49
|
+
# Add the language subfolder for all except the default (first) language.
|
50
|
+
dir = index == 0 ? permalink : File.join(language_public, permalink)
|
51
|
+
|
52
|
+
# Create the indicator page.
|
53
|
+
site.collections['indicators'].docs << IndicatorPage.new(site, site.source, dir, inid, language, layout)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
# Create the indicator settings configuration/metadata/data pages.
|
57
|
+
do_indicator_config_forms = form_settings_config && form_settings_config['enabled']
|
58
|
+
do_indicator_meta_forms = form_settings_meta && form_settings_meta['enabled']
|
59
|
+
do_indicator_data_forms = form_settings_data && form_settings_data['enabled']
|
60
|
+
use_translated_metadata = form_settings_meta && form_settings_meta['translated']
|
61
|
+
if do_indicator_config_forms || do_indicator_meta_forms || do_indicator_data_forms
|
62
|
+
|
63
|
+
metadata = {}
|
64
|
+
if opensdg_translated_builds(site)
|
65
|
+
if site.data.has_key?('untranslated')
|
66
|
+
metadata = site.data['untranslated']['meta']
|
67
|
+
else
|
68
|
+
default_language = language_config[0]
|
69
|
+
metadata = site.data[default_language]['meta']
|
70
|
+
end
|
71
|
+
else
|
72
|
+
metadata = site.data['meta']
|
73
|
+
end
|
74
|
+
|
75
|
+
metadata_by_language = {}
|
76
|
+
language_config.each do |language|
|
77
|
+
if opensdg_translated_builds(site)
|
78
|
+
metadata_by_language[language] = site.data[language]['meta']
|
79
|
+
else
|
80
|
+
metadata_by_language[language] = site.data['meta']
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Because we have config forms for indicator config or meta/data, we
|
85
|
+
# take over the meta/data_edit_url and configuration_edit_url settings
|
86
|
+
# here with simple relative links.
|
87
|
+
if do_indicator_config_forms
|
88
|
+
site.config['configuration_edit_url'] = 'config'
|
89
|
+
end
|
90
|
+
|
91
|
+
if do_indicator_meta_forms
|
92
|
+
site.config['metadata_edit_url'] = 'metadata'
|
93
|
+
end
|
94
|
+
|
95
|
+
if do_indicator_data_forms
|
96
|
+
site.config['data_edit_url'] = 'data'
|
97
|
+
end
|
98
|
+
|
99
|
+
# Loop through the indicators (using metadata as a list).
|
100
|
+
if !metadata.empty?
|
101
|
+
# Loop through the languages.
|
102
|
+
language_config.each_with_index do |language, index|
|
103
|
+
# Get the "public language" (for URLs) which may be different.
|
104
|
+
language_public = language
|
105
|
+
if languages_public[language]
|
106
|
+
language_public = languages_public[language]
|
107
|
+
end
|
108
|
+
metadata.each do |inid, meta|
|
109
|
+
permalink = inid
|
110
|
+
if (meta.has_key?('permalink') and meta['permalink'] != '')
|
111
|
+
permalink = meta['permalink']
|
112
|
+
end
|
113
|
+
dir_base = File.join(permalink)
|
114
|
+
if index != 0
|
115
|
+
dir_base = File.join(language_public, permalink)
|
116
|
+
end
|
117
|
+
|
118
|
+
if do_indicator_config_forms
|
119
|
+
dir = File.join(dir_base, 'config')
|
120
|
+
title = opensdg_translate_key('indicator.edit_configuration', translations, language)
|
121
|
+
config_type = 'indicator'
|
122
|
+
site.collections['pages'].docs << IndicatorConfigPage.new(site, site.source, dir, inid, language, meta, title, config_type, form_settings_config)
|
123
|
+
end
|
124
|
+
|
125
|
+
if do_indicator_meta_forms
|
126
|
+
metadata_to_use = meta
|
127
|
+
if use_translated_metadata
|
128
|
+
metadata_to_use = metadata_by_language[language][inid]
|
129
|
+
end
|
130
|
+
dir = File.join(dir_base, 'metadata')
|
131
|
+
title = opensdg_translate_key('indicator.edit_metadata', translations, language)
|
132
|
+
config_type = 'metadata'
|
133
|
+
site.collections['pages'].docs << IndicatorConfigPage.new(site, site.source, dir, inid, language, metadata_to_use, title, config_type, form_settings_meta)
|
134
|
+
end
|
135
|
+
|
136
|
+
if do_indicator_data_forms
|
137
|
+
dir = File.join(dir_base, 'data')
|
138
|
+
title = opensdg_translate_key('indicator.edit_data', translations, language)
|
139
|
+
site.collections['pages'].docs << IndicatorDataPage.new(site, site.source, dir, inid, language, title, form_settings_data)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# A Page subclass used in the `CreateIndicators` class for the indicators.
|
150
|
+
class IndicatorPage < Jekyll::Page
|
151
|
+
def initialize(site, base, dir, inid, language, layout)
|
152
|
+
@site = site
|
153
|
+
@base = base
|
154
|
+
@dir = dir
|
155
|
+
@name = 'index.html'
|
156
|
+
|
157
|
+
self.process(@name)
|
158
|
+
self.data = {}
|
159
|
+
self.data['indicator_number'] = inid.gsub('-', '.')
|
160
|
+
self.data['layout'] = layout
|
161
|
+
if site.config['bootstrap_5']
|
162
|
+
self.data['layout'] = 'indicator-bootstrap5'
|
163
|
+
end
|
164
|
+
self.data['language'] = language
|
165
|
+
# Backwards compatibility:
|
166
|
+
self.data['indicator'] = self.data['indicator_number']
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# A Page subclass used in the `CreateIndicators` class for the indicator config forms.
|
171
|
+
class IndicatorConfigPage < Jekyll::Page
|
172
|
+
def initialize(site, base, dir, inid, language, meta, title, config_type, form_settings)
|
173
|
+
@site = site
|
174
|
+
@base = base
|
175
|
+
@dir = dir
|
176
|
+
@name = 'index.html'
|
177
|
+
|
178
|
+
self.process(@name)
|
179
|
+
self.data = {}
|
180
|
+
self.data['language'] = language
|
181
|
+
self.data['indicator_number'] = inid
|
182
|
+
self.data['config_type'] = config_type
|
183
|
+
self.data['layout'] = 'config-builder'
|
184
|
+
self.data['meta'] = meta
|
185
|
+
self.data['title'] = title + ': ' + inid.gsub('-', '.')
|
186
|
+
self.data['config_filename'] = inid + '.yml'
|
187
|
+
self.data['form_settings'] = form_settings
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# A Page subclass used in the `CreateIndicators` class for the indicator data forms.
|
192
|
+
class IndicatorDataPage < Jekyll::Page
|
193
|
+
def initialize(site, base, dir, inid, language, title, form_settings)
|
194
|
+
@site = site
|
195
|
+
@base = base
|
196
|
+
@dir = dir
|
197
|
+
@name = 'index.html'
|
198
|
+
|
199
|
+
self.process(@name)
|
200
|
+
self.data = {}
|
201
|
+
self.data['language'] = language
|
202
|
+
self.data['indicator_number'] = inid
|
203
|
+
self.data['layout'] = 'data-editor'
|
204
|
+
self.data['title'] = title + ': ' + inid.gsub('-', '.')
|
205
|
+
self.data['config_filename'] = 'indicator_' + inid
|
206
|
+
self.data['form_settings'] = form_settings
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|