jekyll-open-sdg-plugins 1.0.0.rc4 → 1.0.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f50ca10fd9350b8b2e3010b8c17e971f38a4e49fc9866c6218f4f1486374a3f
4
- data.tar.gz: 956ad212e0d4288410d4c121ad41d761a50e4e7ad4242db30f956db7310514de
3
+ metadata.gz: ddb67e20c43456b22e036b6eb4bd15c6b97347a41a4df12c41e5b900f3667db6
4
+ data.tar.gz: 40fe001e82c32aee1f9861f989d2fa78acc84de643d6f23fa919388d9e13321a
5
5
  SHA512:
6
- metadata.gz: 559450040341021d19676dc1a57fed8cfadc42662ddeea40e7dd684e2dc57dd28735a62c27ea6aa594f3d030254cbd4fde9077cd8e632537e9feb7da51b0d754
7
- data.tar.gz: 0af25756fd6504bb2d658fd62788386a57f5b7bea83435a276a0c4472c54f745070eea22f03e2ef8a1e5284e6052131f8173bc5e4b1faa2b54a2c26c168b85f9
6
+ metadata.gz: 1573ee2f00780f71aacd3c369baf518d7e01e6ec1f3c95c18a585a99609fa6fecdce61ac38ea154d0be555e2c1140f2514e5aa2da9925d0f606cb12f5b654a5d
7
+ data.tar.gz: 5229e6d494619d2763781dab24f8bfed67f0f9907a10eb2d2e37882cdce7bcc839c1ee816a57d46893d358e1229e6c300095619d51fcb2fc3bbb9ccd915ac826
@@ -35,13 +35,65 @@ module JekyllOpenSdgPlugins
35
35
  end
36
36
 
37
37
  # Compute a URL for an item, given it's number.
38
- def get_url(baseurl, language, default_language, number)
38
+ def get_url(baseurl, language, number, languages, languages_public)
39
+
40
+ default_language = languages[0]
41
+ language_public = language
42
+ if languages_public && languages_public[language]
43
+ language_public = languages_public[language]
44
+ end
45
+ if baseurl == ''
46
+ baseurl = '/'
47
+ end
48
+ if default_language != language
49
+ baseurl += language_public + '/'
50
+ end
51
+ if !baseurl.start_with? '/'
52
+ baseurl = '/' + baseurl
53
+ end
54
+ if !baseurl.end_with? '/'
55
+ baseurl = baseurl + '/'
56
+ end
57
+
39
58
  number = number.gsub('.', '-')
40
- url = baseurl
59
+ baseurl + number
60
+ end
61
+
62
+ # Get a Hash of all the URLs based on one particular one.
63
+ def get_all_urls(url, language, languages, languages_public)
64
+ language_public = language
65
+ if languages_public && languages_public[language]
66
+ language_public = languages_public[language]
67
+ end
68
+
69
+ # First figure out the language-free URL.
70
+ default_language = languages[0]
71
+ if language == default_language
72
+ url_without_language = url
73
+ else
74
+ url_without_language = url.gsub('/' + language_public + '/', '/')
75
+ end
76
+
77
+ urls = {
78
+ language => url
79
+ }
41
80
  if language != default_language
42
- url += '/' + language
81
+ urls[default_language] = url_without_language
43
82
  end
44
- url + '/' + number
83
+ languages.each do |other_language|
84
+ if other_language == language
85
+ next
86
+ end
87
+ if other_language == default_language
88
+ next
89
+ end
90
+ other_language_public = other_language
91
+ if languages_public && languages_public[other_language]
92
+ other_language_public = languages_public[other_language]
93
+ end
94
+ urls[other_language] = '/' + other_language_public + url_without_language
95
+ end
96
+ urls
45
97
  end
46
98
 
47
99
  # Compute a URL for tha goal image, given it's number.
@@ -86,11 +138,10 @@ module JekyllOpenSdgPlugins
86
138
 
87
139
  # Some general variables needed below.
88
140
  translations = site.data['translations']
89
- default_language = site.config['languages'][0]
141
+ languages = site.config['languages']
142
+ languages_public = site.config['languages_public']
143
+ default_language = languages[0]
90
144
  baseurl = site.config['baseurl']
91
- if baseurl == ''
92
- baseurl = '/'
93
- end
94
145
  goal_image_base = site.config['goal_image_base']
95
146
 
96
147
  # These keys are flagged as "protected" here so that we can make sure that
@@ -116,7 +167,7 @@ module JekyllOpenSdgPlugins
116
167
  already_added = {}
117
168
 
118
169
  # Set up some empty hashes, per language.
119
- site.config['languages'].each do |language|
170
+ languages.each do |language|
120
171
  available_goals[language] = []
121
172
  available_targets[language] = []
122
173
  available_indicators[language] = []
@@ -134,7 +185,7 @@ module JekyllOpenSdgPlugins
134
185
  target_translation_key = 'global_targets.' + target_number.gsub('.', '-')
135
186
  indicator_translation_key = 'global_indicators.' + indicator_number.gsub('.', '-')
136
187
 
137
- site.config['languages'].each do |language|
188
+ languages.each do |language|
138
189
  global_goal = {
139
190
  'name' => opensdg_translate_key(goal_translation_key + '-title', translations, language),
140
191
  # TODO: More global metadata about goals?
@@ -173,7 +224,7 @@ module JekyllOpenSdgPlugins
173
224
  'slug' => goal_number.gsub('.', '-'),
174
225
  'name' => opensdg_translate_key(goal_translation_key + '-title', translations, language),
175
226
  'short' => opensdg_translate_key(goal_translation_key + '-short', translations, language),
176
- 'url' => get_url(baseurl, language, default_language, goal_number),
227
+ 'url' => get_url(baseurl, language, goal_number, languages, languages_public),
177
228
  'icon' => get_goal_image(goal_image_base, language, goal_number),
178
229
  'sort' => get_sort_order(goal_number),
179
230
  'global' => global_goal,
@@ -209,7 +260,7 @@ module JekyllOpenSdgPlugins
209
260
  'number' => indicator_number,
210
261
  'slug' => indicator_number.gsub('.', '-'),
211
262
  'name' => opensdg_translate_key(indicator_name, translations, language),
212
- 'url' => get_url(baseurl, language, default_language, indicator_number),
263
+ 'url' => get_url(baseurl, language, indicator_number, languages, languages_public),
213
264
  'sort' => get_sort_order(indicator_number),
214
265
  'goal_number' => goal_number,
215
266
  'target_number' => target_number,
@@ -226,7 +277,7 @@ module JekyllOpenSdgPlugins
226
277
  end
227
278
 
228
279
  # Sort all the items.
229
- site.config['languages'].each do |lang|
280
+ languages.each do |lang|
230
281
  available_goals[lang] = available_goals[lang].sort_by { |x| x['sort'] }
231
282
  available_targets[lang] = available_targets[lang].sort_by { |x| x['sort'] }
232
283
  available_indicators[lang] = available_indicators[lang].sort_by { |x| x['sort'] }
@@ -237,8 +288,7 @@ module JekyllOpenSdgPlugins
237
288
  # page, goal, and indicator across the site. This may be a bit memory-
238
289
  # intensive during the Jekyll build, but it is nice to have it available
239
290
  # for consistency.
240
- collections = ['pages', 'goals', 'indicators']
241
- collections.each do |collection|
291
+ site.collections.keys.each do |collection|
242
292
  site.collections[collection].docs.each do |doc|
243
293
  # Ensure it has a language.
244
294
  if !doc.data.has_key? 'language'
@@ -250,29 +300,8 @@ module JekyllOpenSdgPlugins
250
300
  doc.data['targets'] = available_targets[language]
251
301
  doc.data['indicators'] = available_indicators[language]
252
302
  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
- if !baseurl.start_with? '/'
269
- baseurl = '/' + baseurl
270
- end
271
- if !baseurl.end_with? '/'
272
- baseurl = baseurl + '/'
273
- end
274
- doc.data['baseurl'] = baseurl
275
- doc.data['language_public'] = language_public
303
+ doc.data['baseurl'] = get_url(baseurl, language, '', languages, languages_public)
304
+ doc.data['url_by_language'] = get_all_urls(doc.url, language, languages, languages_public)
276
305
 
277
306
  if collection == 'indicators'
278
307
  # For indicators we also set the current indicator/target/goal.
@@ -1,3 +1,3 @@
1
1
  module JekyllOpenSdgPlugins
2
- VERSION = "1.0.0.rc4".freeze
2
+ VERSION = "1.0.0.rc5".freeze
3
3
  end
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: 1.0.0.rc4
4
+ version: 1.0.0.rc5
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-15 00:00:00.000000000 Z
11
+ date: 2019-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll