jekyll-open-sdg-plugins 0.0.16 → 1.0.0.pre.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +80 -0
- data/lib/jekyll-open-sdg-plugins.rb +1 -1
- data/lib/jekyll-open-sdg-plugins/create_goals.rb +3 -1
- data/lib/jekyll-open-sdg-plugins/create_indicators.rb +3 -1
- data/lib/jekyll-open-sdg-plugins/sdg_variables.rb +342 -0
- data/lib/jekyll-open-sdg-plugins/version.rb +1 -1
- metadata +6 -6
- data/lib/jekyll-open-sdg-plugins/get_indicator_name.rb +0 -143
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad4f6ae4555c57263d1c047cf54ac804eb19683e5058afbb5a0b5b3aa9aced2f
|
4
|
+
data.tar.gz: 78d24d62d762145f03bbbdfed1f3025143c9877031dae119f9f87da623bda420
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 482823ea2ba440a3a105905d0ae173b4f5fee0c36bdf939e23615a63cec0d8c31cfa6f267bfd280ded1954d8a5e62cad007605ef07bc86bffa37ff6dd2267101
|
7
|
+
data.tar.gz: 1cf3d356d08972d88966dace5dad7286a4684d0209b38ae8be0fd5b885877f7aa1c19cb4504b8dde50ee98901df6b22d127149c6abb8bcb7f7c96f803bbdd3f5
|
data/README.md
CHANGED
@@ -71,3 +71,83 @@ remote_translations:
|
|
71
71
|
```
|
72
72
|
|
73
73
|
For those interested in switching to this convenience feature, note that this makes the "jekyll_get_json" and "remotedatabaseurl" settings obsolete; so they can be removed.
|
74
|
+
|
75
|
+
## 7. Provide standard variables on all pages, for use in templates
|
76
|
+
|
77
|
+
This feature provides access to Hashes for goals, targets, and indicators. Each
|
78
|
+
contains the following keys:
|
79
|
+
* number (eg, "1" for a goal, "1.1" for a target, "1.1.1" for an indicator)
|
80
|
+
* slug (eg, "1" for a goal, "1-1", for a target, "1-1-1" for an indicator)
|
81
|
+
* name (the fully-translated name of the goal/target/indicator
|
82
|
+
* sort (a string suitable for use in sorting the goals/targets/indicators)
|
83
|
+
* global (an equivalent Hash containing specifically "global" versions)
|
84
|
+
|
85
|
+
Additionally, indicators contain:
|
86
|
+
* url (the URL of that indicator's page)
|
87
|
+
* goal_number (the number of that indicator's goal)
|
88
|
+
* target_number (the number of that indicator's target)
|
89
|
+
* [all the indicator's metadata fields]
|
90
|
+
|
91
|
+
Additionally, targets contain:
|
92
|
+
* goal_number (the number of that target's goal)
|
93
|
+
|
94
|
+
Additionally, goals contain:
|
95
|
+
* url (the URL of that goal's page)
|
96
|
+
* icon (the URL of that goal's icon)
|
97
|
+
* short (the short version of the goal name, translated)
|
98
|
+
|
99
|
+
The following variables can be used on ALL pages:
|
100
|
+
|
101
|
+
* goals : Array of goals
|
102
|
+
* targets : Array of targets
|
103
|
+
* indicators : Array of indicators
|
104
|
+
* baseurl: A page-specific version of site.baseurl, taking language into account
|
105
|
+
* language: The language code for the current page
|
106
|
+
* language_public: The "public" language code, which may be different from the
|
107
|
+
language code.
|
108
|
+
* t: A hash of all the compiled translations in the current language
|
109
|
+
|
110
|
+
The following variables can be used on all indicator pages:
|
111
|
+
|
112
|
+
* goal : the current goal
|
113
|
+
* target : the current target
|
114
|
+
* indicator : the current indicator
|
115
|
+
|
116
|
+
The following variables can be used on all goal pages:
|
117
|
+
|
118
|
+
* goal : the current goal
|
119
|
+
|
120
|
+
Examples of usage:
|
121
|
+
|
122
|
+
Printing titles for all available indicators in Goal 2:
|
123
|
+
```
|
124
|
+
{% assign indicators = page.indicators | where: "goal_number", "2" %}
|
125
|
+
{% for indicator in indicators %}
|
126
|
+
{{ indicator.name }}
|
127
|
+
{% endfor %}
|
128
|
+
```
|
129
|
+
|
130
|
+
Printing the short name for the current goal, on a goal page:
|
131
|
+
```
|
132
|
+
{{ page.goal.short }}
|
133
|
+
```
|
134
|
+
|
135
|
+
Printing the name of all targets in a particular, on that goal page:
|
136
|
+
```
|
137
|
+
{% assign targets = page.targets | where: "goal_number", page.goal.number %}
|
138
|
+
{% for target in targets %}
|
139
|
+
{{ target.name }}
|
140
|
+
{% endfor %}
|
141
|
+
|
142
|
+
## 8. Lookup goals/targets/indicators by ID
|
143
|
+
|
144
|
+
The hashes detailed above in #7 can also be looked up by id, with the `sdg_lookup` filter.
|
145
|
+
|
146
|
+
Examples of usage:
|
147
|
+
|
148
|
+
Looking up target 7.1 and printing its name
|
149
|
+
|
150
|
+
```
|
151
|
+
{% assign target = '7.1' | sdg_lookup %}
|
152
|
+
{{ target.name }}
|
153
|
+
```
|
@@ -5,7 +5,7 @@ require_relative "jekyll-open-sdg-plugins/translate_key"
|
|
5
5
|
require_relative "jekyll-open-sdg-plugins/create_indicators"
|
6
6
|
require_relative "jekyll-open-sdg-plugins/create_goals"
|
7
7
|
require_relative "jekyll-open-sdg-plugins/create_pages"
|
8
|
-
require_relative "jekyll-open-sdg-plugins/
|
8
|
+
require_relative "jekyll-open-sdg-plugins/sdg_variables"
|
9
9
|
|
10
10
|
module JekyllOpenSdgPlugins
|
11
11
|
end
|
@@ -53,9 +53,11 @@ module JekyllOpenSdgPlugins
|
|
53
53
|
|
54
54
|
self.process(@name)
|
55
55
|
self.data = {}
|
56
|
-
self.data['
|
56
|
+
self.data['goal_number'] = goal.to_s
|
57
57
|
self.data['language'] = language
|
58
58
|
self.data['layout'] = layout
|
59
|
+
# Backwards compatibility:
|
60
|
+
self.data['sdg_goal'] = self.data['goal_number']
|
59
61
|
end
|
60
62
|
end
|
61
63
|
end
|
@@ -47,9 +47,11 @@ module JekyllOpenSdgPlugins
|
|
47
47
|
|
48
48
|
self.process(@name)
|
49
49
|
self.data = {}
|
50
|
-
self.data['
|
50
|
+
self.data['indicator_number'] = inid.gsub('-', '.')
|
51
51
|
self.data['layout'] = layout
|
52
52
|
self.data['language'] = language
|
53
|
+
# Backwards compatibility:
|
54
|
+
self.data['indicator'] = self.data['indicator_number']
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -0,0 +1,342 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "helpers"
|
3
|
+
|
4
|
+
module JekyllOpenSdgPlugins
|
5
|
+
class SDGVariables < Jekyll::Generator
|
6
|
+
safe true
|
7
|
+
priority :lowest
|
8
|
+
|
9
|
+
# Get a goal number from an indicator number.
|
10
|
+
def get_goal_number(indicator_number)
|
11
|
+
parts = indicator_number.split('.')
|
12
|
+
parts[0]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get a target number from an indicator number.
|
16
|
+
def get_target_number(indicator_number)
|
17
|
+
parts = indicator_number.split('.')
|
18
|
+
parts[0] + '.' + parts[1]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Make any goal/target/indicator number suitable for use in sorting.
|
22
|
+
def get_sort_order(number)
|
23
|
+
if number.is_a? Numeric
|
24
|
+
number = number.to_s
|
25
|
+
end
|
26
|
+
sort_order = ''
|
27
|
+
parts = number.split('.')
|
28
|
+
parts.each do |part|
|
29
|
+
if part.length == 1
|
30
|
+
part = '0' + part
|
31
|
+
end
|
32
|
+
sort_order += part
|
33
|
+
end
|
34
|
+
sort_order
|
35
|
+
end
|
36
|
+
|
37
|
+
# Compute a URL for an item, given it's number.
|
38
|
+
def get_url(baseurl, language, default_language, number)
|
39
|
+
number = number.gsub('.', '-')
|
40
|
+
url = baseurl
|
41
|
+
if language != default_language
|
42
|
+
url += '/' + language
|
43
|
+
end
|
44
|
+
url + '/' + number
|
45
|
+
end
|
46
|
+
|
47
|
+
# Compute a URL for tha goal image, given it's number.
|
48
|
+
def get_goal_image(goal_image_base, language, number)
|
49
|
+
goal_image_base + '/' + language + '/' + number + '.png'
|
50
|
+
end
|
51
|
+
|
52
|
+
# This creates variables for use in Liquid templates under "page".
|
53
|
+
# We'll create lists of goals, targets, and indicators. These will be put
|
54
|
+
# on the page object. Eg: page.goals. In order to generate these lists
|
55
|
+
# we will make use of the metadata. Each item in the list will be a hash
|
56
|
+
# containing these keys:
|
57
|
+
# - name (translated)
|
58
|
+
# - number (the "id" or number, eg: 1, 1.2, 1.2.1, etc.)
|
59
|
+
# - slug (version of 'number' but with dashes instead of dots)
|
60
|
+
# - sort (for the purposes of sorting the items, if needed)
|
61
|
+
# - global (a Hash containing any equivalent global metadata)
|
62
|
+
# The goal hashes contain additional keys:
|
63
|
+
# - short (the translated short version of the name)
|
64
|
+
# - icon (path to the translated icon)
|
65
|
+
# - url (path to the goal page)
|
66
|
+
# The target hashes contain additional keys:
|
67
|
+
# - goal_number (the goal number for this target)
|
68
|
+
# The indicator hashes contain additional keys:
|
69
|
+
# - url (path to the indicator page)
|
70
|
+
# - goal_number (the goal number for this indicator)
|
71
|
+
# - target_number (the target number for this indicator)
|
72
|
+
# - [all metadata fields from the indicator]
|
73
|
+
# The lists are:
|
74
|
+
# - goals
|
75
|
+
# - targets
|
76
|
+
# - indicators
|
77
|
+
# Additionally, on indicator pages themselves, there are variables for
|
78
|
+
# the current goal/target/indicator:
|
79
|
+
# - goal
|
80
|
+
# - target
|
81
|
+
# - indicator
|
82
|
+
# Similarly, on goal pages themselves, there are variables for the current
|
83
|
+
# goal:
|
84
|
+
# - goal
|
85
|
+
def generate(site)
|
86
|
+
|
87
|
+
# Some general variables needed below.
|
88
|
+
translations = site.data['translations']
|
89
|
+
default_language = site.config['languages'][0]
|
90
|
+
baseurl = site.config['baseurl']
|
91
|
+
if baseurl == ''
|
92
|
+
baseurl = '/'
|
93
|
+
end
|
94
|
+
goal_image_base = site.config['goal_image_base']
|
95
|
+
|
96
|
+
# These keys are flagged as "protected" here so that we can make sure that
|
97
|
+
# country-specific metadata doesn't use any of these fields.
|
98
|
+
protected_keys = ['goals', 'goal', 'targets', 'target', 'indicators',
|
99
|
+
'indicator', 'language', 'name', 'number', 'sort', 'global', 'url',
|
100
|
+
'goal_number', 'target_number'
|
101
|
+
]
|
102
|
+
|
103
|
+
# Figure out from our translations the global indicator numbers.
|
104
|
+
global_inids = translations[default_language]['global_indicators'].keys
|
105
|
+
global_inids = global_inids.select { |x| x.end_with? '-title' }
|
106
|
+
global_inids = global_inids.map { |x| x.gsub('-title', '').gsub('-', '.') }
|
107
|
+
|
108
|
+
# For available indicators, we simply map the "indicators" collection.
|
109
|
+
available_inids = site.collections['indicators'].docs.select { |x| x.data['language'] == default_language }
|
110
|
+
available_inids = available_inids.map { |x| x.data['indicator'] }
|
111
|
+
available_indicators = {}
|
112
|
+
available_targets = {}
|
113
|
+
available_goals = {}
|
114
|
+
|
115
|
+
# Some throwaway variables to keep track of what has been added.
|
116
|
+
already_added = {}
|
117
|
+
|
118
|
+
# Set up some empty hashes, per language.
|
119
|
+
site.config['languages'].each do |language|
|
120
|
+
available_goals[language] = []
|
121
|
+
available_targets[language] = []
|
122
|
+
available_indicators[language] = []
|
123
|
+
already_added[language] = []
|
124
|
+
end
|
125
|
+
|
126
|
+
# Populate the hashes.
|
127
|
+
available_inids.each do |indicator_number|
|
128
|
+
goal_number = get_goal_number(indicator_number)
|
129
|
+
target_number = get_target_number(indicator_number)
|
130
|
+
is_global_indicator = global_inids.index(indicator_number) != nil
|
131
|
+
# To get the name of global stuff, we can use predicable translation
|
132
|
+
# keys from the SDG Translations project. Eg: global_goals.1-title
|
133
|
+
goal_translation_key = 'global_goals.' + goal_number
|
134
|
+
target_translation_key = 'global_targets.' + target_number.gsub('.', '-')
|
135
|
+
indicator_translation_key = 'global_indicators.' + indicator_number.gsub('.', '-')
|
136
|
+
|
137
|
+
site.config['languages'].each do |language|
|
138
|
+
global_goal = {
|
139
|
+
'name' => opensdg_translate_key(goal_translation_key + '-title', translations, language),
|
140
|
+
# TODO: More global metadata about goals?
|
141
|
+
}
|
142
|
+
global_target = {
|
143
|
+
'name' => opensdg_translate_key(target_translation_key + '-title', translations, language),
|
144
|
+
# TODO: More global metadata about targets?
|
145
|
+
}
|
146
|
+
global_indicator = {}
|
147
|
+
if is_global_indicator
|
148
|
+
global_indicator = {
|
149
|
+
'name' => opensdg_translate_key(indicator_translation_key + '-title', translations, language),
|
150
|
+
# TODO: More global metadata about indicators?
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
# We have to get the metadata for the indicator/language.
|
155
|
+
meta = {}
|
156
|
+
# Currently the meta keys are dash-delimited. This is a little
|
157
|
+
# arbitrary (it's because they came from filenames) and could maybe
|
158
|
+
# be changed eventually to dot-delimited for consistency.
|
159
|
+
meta_key = indicator_number.gsub('.', '-')
|
160
|
+
# The location of the metadata is different depending on whether we are
|
161
|
+
# using "translated_builds" or not.
|
162
|
+
if site.config['translated_builds']
|
163
|
+
meta = site.data[language]['meta'][meta_key]
|
164
|
+
else
|
165
|
+
meta = site.data['meta'][meta_key]
|
166
|
+
end
|
167
|
+
|
168
|
+
# Set the goal for this language, once only.
|
169
|
+
if already_added[language].index(goal_number) == nil
|
170
|
+
already_added[language].push(goal_number)
|
171
|
+
available_goal = {
|
172
|
+
'number' => goal_number,
|
173
|
+
'slug' => goal_number.gsub('.', '-'),
|
174
|
+
'name' => opensdg_translate_key(goal_translation_key + '-title', translations, language),
|
175
|
+
'short' => opensdg_translate_key(goal_translation_key + '-short', translations, language),
|
176
|
+
'url' => get_url(baseurl, language, default_language, goal_number),
|
177
|
+
'icon' => get_goal_image(goal_image_base, language, goal_number),
|
178
|
+
'sort' => get_sort_order(goal_number),
|
179
|
+
'global' => global_goal,
|
180
|
+
}
|
181
|
+
available_goals[language].push(available_goal)
|
182
|
+
end
|
183
|
+
# Set the target for this language, once only.
|
184
|
+
if already_added[language].index(target_number) == nil
|
185
|
+
already_added[language].push(target_number)
|
186
|
+
available_target = {
|
187
|
+
'number' => target_number,
|
188
|
+
'slug' => target_number.gsub('.', '-'),
|
189
|
+
'name' => opensdg_translate_key(target_translation_key + '-title', translations, language),
|
190
|
+
'sort' => get_sort_order(target_number),
|
191
|
+
'goal_number' => goal_number,
|
192
|
+
'global' => global_target,
|
193
|
+
}
|
194
|
+
available_targets[language].push(available_target)
|
195
|
+
end
|
196
|
+
# Set the indicator for this language. Unfortunately we are currently
|
197
|
+
# using two possible fields for the indicator name:
|
198
|
+
# - indicator_name
|
199
|
+
# - indicator_name_national
|
200
|
+
# TODO: Eventually standardize around 'indicator_name' and drop support
|
201
|
+
# for 'indicator_name_national'.
|
202
|
+
indicator_name = ''
|
203
|
+
if meta.has_key? 'indicator_name_national'
|
204
|
+
indicator_name = meta['indicator_name_national']
|
205
|
+
else
|
206
|
+
indicator_name = meta['indicator_name']
|
207
|
+
end
|
208
|
+
available_indicator = {
|
209
|
+
'number' => indicator_number,
|
210
|
+
'slug' => indicator_number.gsub('.', '-'),
|
211
|
+
'name' => opensdg_translate_key(indicator_name, translations, language),
|
212
|
+
'url' => get_url(baseurl, language, default_language, indicator_number),
|
213
|
+
'sort' => get_sort_order(indicator_number),
|
214
|
+
'goal_number' => goal_number,
|
215
|
+
'target_number' => target_number,
|
216
|
+
'global' => global_indicator,
|
217
|
+
}
|
218
|
+
# Translate and add any metadata.
|
219
|
+
meta.each do |key, value|
|
220
|
+
if !protected_keys.include? key
|
221
|
+
available_indicator[key] = opensdg_translate_key(value, translations, language)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
available_indicators[language].push(available_indicator)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
# Sort all the items.
|
229
|
+
site.config['languages'].each do |lang|
|
230
|
+
available_goals[lang] = available_goals[lang].sort_by { |x| x['sort'] }
|
231
|
+
available_targets[lang] = available_targets[lang].sort_by { |x| x['sort'] }
|
232
|
+
available_indicators[lang] = available_indicators[lang].sort_by { |x| x['sort'] }
|
233
|
+
end
|
234
|
+
|
235
|
+
# Next set the stuff on each doc in certain collections, according
|
236
|
+
# to the doc's language. We'll be putting the global stuff on every
|
237
|
+
# page, goal, and indicator across the site. This may be a bit memory-
|
238
|
+
# intensive during the Jekyll build, but it is nice to have it available
|
239
|
+
# for consistency.
|
240
|
+
collections = ['pages', 'goals', 'indicators']
|
241
|
+
collections.each do |collection|
|
242
|
+
site.collections[collection].docs.each do |doc|
|
243
|
+
# Ensure it has a language.
|
244
|
+
if !doc.data.has_key? 'language'
|
245
|
+
doc.data['language'] = default_language
|
246
|
+
end
|
247
|
+
language = doc.data['language']
|
248
|
+
# Set these on the page object.
|
249
|
+
doc.data['goals'] = available_goals[language]
|
250
|
+
doc.data['targets'] = available_targets[language]
|
251
|
+
doc.data['indicators'] = available_indicators[language]
|
252
|
+
doc.data['t'] = site.data['translations'][language]
|
253
|
+
# Also figure out the language-specific baseurl and the "public"
|
254
|
+
# language code, in case it is different from the actual language.
|
255
|
+
language_public = language
|
256
|
+
if site.config['languages_public']
|
257
|
+
if site.config['languages_public'][language]
|
258
|
+
language_public = site.config['languages_public'][language]
|
259
|
+
end
|
260
|
+
end
|
261
|
+
baseurl = site.config['baseurl']
|
262
|
+
if baseurl == ''
|
263
|
+
baseurl = '/'
|
264
|
+
end
|
265
|
+
if default_language != language
|
266
|
+
baseurl += language_public + '/'
|
267
|
+
end
|
268
|
+
doc.data['baseurl'] = baseurl
|
269
|
+
doc.data['language_public'] = language_public
|
270
|
+
|
271
|
+
if collection == 'indicators'
|
272
|
+
# For indicators we also set the current indicator/target/goal.
|
273
|
+
if doc.data.has_key? 'indicator_number'
|
274
|
+
indicator_number = doc.data['indicator_number']
|
275
|
+
elsif doc.data.has_key? 'indicator'
|
276
|
+
# Backwards compatibility.
|
277
|
+
indicator_number = doc.data['indicator']
|
278
|
+
else
|
279
|
+
raise "Error: An indicator does not have 'indicator_number' property."
|
280
|
+
end
|
281
|
+
goal_number = get_goal_number(indicator_number)
|
282
|
+
target_number = get_target_number(indicator_number)
|
283
|
+
doc.data['goal'] = available_goals[language].find {|x| x['number'] == goal_number}
|
284
|
+
doc.data['target'] = available_targets[language].find {|x| x['number'] == target_number}
|
285
|
+
doc.data['indicator'] = available_indicators[language].find {|x| x['number'] == indicator_number}
|
286
|
+
elsif collection == 'goals'
|
287
|
+
# For goals we also set the current goal.
|
288
|
+
if doc.data.has_key? 'goal_number'
|
289
|
+
goal_number = doc.data['goal_number']
|
290
|
+
elsif doc.data.has_key? 'sdg_goal'
|
291
|
+
# Backwards compatibility.
|
292
|
+
goal_number = doc.data['sdg_goal']
|
293
|
+
else
|
294
|
+
raise "Error: A goal does not have 'goal_number' property."
|
295
|
+
end
|
296
|
+
doc.data['goal'] = available_goals[language].find {|x| x['number'] == goal_number}
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
# Finally let's set all these on the site object so that they can be
|
302
|
+
# easily looked up later.
|
303
|
+
lookup = {}
|
304
|
+
available_goals.each do |language, items|
|
305
|
+
lookup[language] = {}
|
306
|
+
items.each do |item|
|
307
|
+
number = item['number']
|
308
|
+
lookup[language][number] = item
|
309
|
+
end
|
310
|
+
end
|
311
|
+
available_targets.each do |language, items|
|
312
|
+
items.each do |item|
|
313
|
+
number = item['number']
|
314
|
+
lookup[language][number] = item
|
315
|
+
end
|
316
|
+
end
|
317
|
+
available_indicators.each do |language, items|
|
318
|
+
items.each do |item|
|
319
|
+
number = item['number']
|
320
|
+
lookup[language][number] = item
|
321
|
+
end
|
322
|
+
end
|
323
|
+
site.data['sdg_lookup'] = lookup
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
module Jekyll
|
329
|
+
module SDGLookup
|
330
|
+
# This provides a "sdg_lookup" filter that takes an id and returns a hash
|
331
|
+
# representation of a goal, target, or indicator.
|
332
|
+
def sdg_lookup(number)
|
333
|
+
number = number.gsub('-', '.')
|
334
|
+
data = @context.registers[:site].data
|
335
|
+
page = @context.environments.first['page']
|
336
|
+
language = page['language']
|
337
|
+
return data['sdg_lookup'][language][number]
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
Liquid::Template.register_filter(Jekyll::SDGLookup)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-open-sdg-plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 1.0.0.pre.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brock Fanning
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -55,9 +55,9 @@ files:
|
|
55
55
|
- lib/jekyll-open-sdg-plugins/create_indicators.rb
|
56
56
|
- lib/jekyll-open-sdg-plugins/create_pages.rb
|
57
57
|
- lib/jekyll-open-sdg-plugins/fetch_remote_data.rb
|
58
|
-
- lib/jekyll-open-sdg-plugins/get_indicator_name.rb
|
59
58
|
- lib/jekyll-open-sdg-plugins/helpers.rb
|
60
59
|
- lib/jekyll-open-sdg-plugins/multilingual_metadata.rb
|
60
|
+
- lib/jekyll-open-sdg-plugins/sdg_variables.rb
|
61
61
|
- lib/jekyll-open-sdg-plugins/translate_key.rb
|
62
62
|
- lib/jekyll-open-sdg-plugins/version.rb
|
63
63
|
homepage: https://github.com/open-sdg/jekyll-open-sdg-plugins
|
@@ -75,12 +75,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - "
|
78
|
+
- - ">"
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
80
|
+
version: 1.3.1
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.7.
|
83
|
+
rubygems_version: 2.7.1
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: Jekyll plugins for use with the Open SDG platform
|
@@ -1,143 +0,0 @@
|
|
1
|
-
require "jekyll"
|
2
|
-
require_relative "helpers"
|
3
|
-
|
4
|
-
module Jekyll
|
5
|
-
module IndicatorName
|
6
|
-
|
7
|
-
# Takes an indicator ID (dot-delimited or dash-delimited) and returns the
|
8
|
-
# translated indicator name (according to the current language). This lookup
|
9
|
-
# is as forgiving as possible, to make sure that something is always there.
|
10
|
-
#
|
11
|
-
# The order of preference in the lookup is:
|
12
|
-
#
|
13
|
-
# 1. "indicator_name_national" in translated metadata - subfolder approach
|
14
|
-
# 2. "indicator_name_national" in translated metadata - translation key approach
|
15
|
-
# 3. If the default language, "indicator_name_national" in non-translated metadata
|
16
|
-
# 4. If a global indicator, translated global indicator name
|
17
|
-
# 5. "indicator_name" in translated metadata - subfolder approach
|
18
|
-
# 6. "indicator_name" in translated metadata - translation key approach
|
19
|
-
# 7. "indicator_name" in non-translated metadata
|
20
|
-
# 8. Finally, fall back to the indicator ID
|
21
|
-
|
22
|
-
def get_indicator_name(inid)
|
23
|
-
|
24
|
-
# Safety code - abort now if id is nil.
|
25
|
-
if inid.nil?
|
26
|
-
return ""
|
27
|
-
end
|
28
|
-
|
29
|
-
# Also make sure it is a string, and otherwise just return it.
|
30
|
-
if not inid.is_a? String
|
31
|
-
return inid
|
32
|
-
end
|
33
|
-
|
34
|
-
# More safety code - abort now if inid is empty.
|
35
|
-
if inid.empty?
|
36
|
-
return ""
|
37
|
-
end
|
38
|
-
|
39
|
-
# Normalize around dash-delimited inids.
|
40
|
-
inid = inid.gsub('.', '-')
|
41
|
-
|
42
|
-
# Some variables to help our lookups later.
|
43
|
-
page = @context.environments.first['page']
|
44
|
-
language = page['language']
|
45
|
-
languages = @context.registers[:site].config['languages']
|
46
|
-
data = @context.registers[:site].data
|
47
|
-
translations = data['translations']
|
48
|
-
meta = data['meta'][inid]
|
49
|
-
|
50
|
-
# The metadata fields that we'll seek, first "override" then "default".
|
51
|
-
override_field = 'indicator_name_national'
|
52
|
-
default_field = 'indicator_name'
|
53
|
-
|
54
|
-
name = false
|
55
|
-
|
56
|
-
# 1. Is there a subfolder translation of the override field?
|
57
|
-
if meta and meta.has_key? language
|
58
|
-
if !name and meta[language].has_key? override_field
|
59
|
-
name = meta[language][override_field]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# 2. Is the override field actually a "translation key"?
|
64
|
-
if !name
|
65
|
-
if meta and meta.has_key? override_field
|
66
|
-
untranslated = meta[override_field]
|
67
|
-
translated = opensdg_translate_key(untranslated, translations, language)
|
68
|
-
if untranslated != translated
|
69
|
-
# If the opensdg_translate_key() function returned something else,
|
70
|
-
# that means it was an actual "translation key".
|
71
|
-
name = translated
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# 3. If this is the default language, use the non-translated override
|
77
|
-
# field, if available.
|
78
|
-
if !name
|
79
|
-
if language == languages[0]
|
80
|
-
if meta and meta.has_key? override_field
|
81
|
-
name = meta[override_field]
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# 4. Is this a global indicator with a translation?
|
87
|
-
if !name
|
88
|
-
title_key = inid + '-title'
|
89
|
-
# For backwards compatibility, look for both dot and dash-delimited keys.
|
90
|
-
title_key_dots = inid.gsub('-', '.') + '-title'
|
91
|
-
if translations.has_key? language
|
92
|
-
if translations[language].has_key? 'global_indicators'
|
93
|
-
if translations[language]['global_indicators'].has_key? title_key
|
94
|
-
name = translations[language]['global_indicators'][title_key]
|
95
|
-
elsif translations[language]['global_indicators'].has_key? title_key_dots
|
96
|
-
name = translations[language]['global_indicators'][title_key_dots]
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# 5. Is there a subfolder translation of the default field?
|
103
|
-
if !name
|
104
|
-
if meta and meta.has_key? language
|
105
|
-
if !name and meta[language].has_key? default_field
|
106
|
-
name = meta[language][default_field]
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# 6. Is the default field actually a "translation key"?
|
112
|
-
if !name
|
113
|
-
if meta and meta.has_key? default_field
|
114
|
-
untranslated = meta[default_field]
|
115
|
-
translated = opensdg_translate_key(untranslated, translations, language)
|
116
|
-
if untranslated != translated
|
117
|
-
# If the opensdg_translate_key() function returned something else,
|
118
|
-
# that means it was an actual "translation key".
|
119
|
-
name = translated
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# 7. Use the non-translated default field, if available.
|
125
|
-
if !name
|
126
|
-
if meta and meta.has_key? default_field
|
127
|
-
name = meta[default_field]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# 8. Still here? Just return the inid.
|
132
|
-
if !name
|
133
|
-
name = inid
|
134
|
-
end
|
135
|
-
|
136
|
-
# Finally return the name with key translation for good measure.
|
137
|
-
return opensdg_translate_key(name, translations, language)
|
138
|
-
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
Liquid::Template.register_filter(Jekyll::IndicatorName)
|