jekyll-open-sdg-plugins 1.6.0.pre.beta1 → 1.7.0.pre.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +16 -16
  3. data/.github/workflows/test-pull-requests.yml +17 -17
  4. data/.gitignore +6 -6
  5. data/LICENSE +21 -21
  6. data/Makefile +33 -33
  7. data/README.md +7 -7
  8. data/jekyll-open-sdg-plugins.gemspec +18 -18
  9. data/lib/jekyll-open-sdg-plugins/backwards_compatibility.rb +64 -61
  10. data/lib/jekyll-open-sdg-plugins/create_goals.rb +85 -85
  11. data/lib/jekyll-open-sdg-plugins/create_indicators.rb +206 -206
  12. data/lib/jekyll-open-sdg-plugins/create_pages.rb +135 -135
  13. data/lib/jekyll-open-sdg-plugins/fetch_remote_data.rb +188 -188
  14. data/lib/jekyll-open-sdg-plugins/helpers.rb +132 -132
  15. data/lib/jekyll-open-sdg-plugins/metadata_schema_to_config.rb +72 -72
  16. data/lib/jekyll-open-sdg-plugins/schema-indicator-config.json +787 -709
  17. data/lib/jekyll-open-sdg-plugins/schema-site-config.json +1652 -1617
  18. data/lib/jekyll-open-sdg-plugins/sdg_variables.rb +614 -549
  19. data/lib/jekyll-open-sdg-plugins/search_index.rb +102 -102
  20. data/lib/jekyll-open-sdg-plugins/site_configuration.rb +73 -52
  21. data/lib/jekyll-open-sdg-plugins/translate_date.rb +122 -122
  22. data/lib/jekyll-open-sdg-plugins/translate_key.rb +20 -20
  23. data/lib/jekyll-open-sdg-plugins/translate_metadata_field.rb +111 -111
  24. data/lib/jekyll-open-sdg-plugins/validate_indicator_config.rb +52 -52
  25. data/lib/jekyll-open-sdg-plugins/validate_site_config.rb +34 -34
  26. data/lib/jekyll-open-sdg-plugins/version.rb +3 -3
  27. data/lib/jekyll-open-sdg-plugins.rb +18 -18
  28. data/tests/Gemfile +7 -7
  29. data/tests/_config.yml +168 -168
  30. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b37fec3e9d58774c1d4bb3b6102a3e37347e92c559e9eafacaa97d793d8584ce
4
- data.tar.gz: b64a110e6f4f6da10c805e221ae3d591bbd65ae026baa5e7a835395790a2857f
3
+ metadata.gz: a20f18058cd335bd8013c7ee57b71e24a89d58233b41a40bb1b9b68935808181
4
+ data.tar.gz: 7500171f49b24af2713419835bddabdb4818a191db2543f5a4f9dc3c71c8790b
5
5
  SHA512:
6
- metadata.gz: 2297001ac108425e4ecb56bc59d16c63ddfc84c85588a67e65c0adde49d83d46db4d0cdc8dc2452700a0118f1cfc50de9b5f578c2e0749596a6835ebb60ad8e7
7
- data.tar.gz: af31105e71d58e3193ab246a1c91e4f4fc04ee34e7013570631e0bcd899fe269f696687e71b7a10f5395cccfe14b935b512cfc7b06741eb1c185b03510ba744d
6
+ metadata.gz: 2aa09b75a8c255eede956558d0f70b1bfaab9ec6cf48d823ed75c8414d66d9e55e52bef746ddbc04561883c6cdc405dea133d734bf8acb70b6c526e8ecaf8870
7
+ data.tar.gz: 5b908df4984d24c1218c49c3e9e53dca009ea86c4bc534ec584784b22977e0d63de6e9087254fbb1c98df5caf202f002ca1cc88d577e529b742ebf4cc5eabf99
data/.editorconfig CHANGED
@@ -1,16 +1,16 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = space
5
- indent_size = 2
6
- trim_trailing_whitespace = true
7
- insert_final_newline = true
8
-
9
- [*.{md,rb,gemspec},Makefile]
10
- charset = utf-8
11
-
12
- [Makefile]
13
- indent_style = tab
14
-
15
- [*.md]
16
- trim_trailing_whitespace = false
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ trim_trailing_whitespace = true
7
+ insert_final_newline = true
8
+
9
+ [*.{md,rb,gemspec},Makefile]
10
+ charset = utf-8
11
+
12
+ [Makefile]
13
+ indent_style = tab
14
+
15
+ [*.md]
16
+ trim_trailing_whitespace = false
@@ -1,17 +1,17 @@
1
- name: Test PRs
2
-
3
- on: [pull_request]
4
-
5
- jobs:
6
- test:
7
-
8
- runs-on: ubuntu-latest
9
-
10
- steps:
11
- - uses: actions/checkout@v1
12
- - name: Set up Ruby 2.6
13
- uses: actions/setup-ruby@v1
14
- with:
15
- ruby-version: 2.6.x
16
- - name: Run all tests
17
- run: make test
1
+ name: Test PRs
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v1
12
+ - name: Set up Ruby 2.6
13
+ uses: actions/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6.x
16
+ - name: Run all tests
17
+ run: make test
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
- _site
2
- .sass-cache
3
- .jekyll-metadata
4
- *.gem
5
- open-sdg/
6
- open-sdg-site-starter/
1
+ _site
2
+ .sass-cache
3
+ .jekyll-metadata
4
+ *.gem
5
+ open-sdg/
6
+ open-sdg-site-starter/
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2019 Brock Fanning <brockfanning@gmail.com> (https://github.com/open-sdg/open-sdg
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Brock Fanning <brockfanning@gmail.com> (https://github.com/open-sdg/open-sdg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Makefile CHANGED
@@ -1,33 +1,33 @@
1
- .PHONY: clean build serve serve.detached
2
- all: test
3
-
4
- clean:
5
- # Stop the detached Jekyll web server.
6
- -pkill -f -9 jekyll
7
- # Delete the builds.
8
- rm -fr open-sdg-site-starter
9
- rm -fr open-sdg
10
-
11
- install: clean
12
- git clone https://github.com/open-sdg/open-sdg-site-starter.git
13
- git clone https://github.com/open-sdg/open-sdg.git
14
- # Copy all the theme files into the site starter.
15
- cp -r open-sdg/_includes/* open-sdg-site-starter/_includes/
16
- cp -r open-sdg/_layouts/* open-sdg-site-starter/_layouts/
17
- cp -r open-sdg/_sass/* open-sdg-site-starter/_sass/
18
- cp -r open-sdg/assets/* open-sdg-site-starter/assets/
19
- # Copy the required files into the site starter.
20
- cp tests/_config.yml open-sdg-site-starter/
21
- cp tests/Gemfile open-sdg-site-starter/
22
- # Create a symlink to our plugin files.
23
- ln -s ../lib/jekyll-open-sdg-plugins open-sdg-site-starter/_plugins
24
- # Install Ruby dependencies.
25
- cd open-sdg-site-starter && bundle install
26
-
27
- build:
28
- cd open-sdg-site-starter && bundle exec jekyll build
29
-
30
- serve:
31
- cd open-sdg-site-starter && bundle exec jekyll serve
32
-
33
- test: install build
1
+ .PHONY: clean build serve serve.detached
2
+ all: test
3
+
4
+ clean:
5
+ # Stop the detached Jekyll web server.
6
+ -pkill -f -9 jekyll
7
+ # Delete the builds.
8
+ rm -fr open-sdg-site-starter
9
+ rm -fr open-sdg
10
+
11
+ install: clean
12
+ git clone https://github.com/open-sdg/open-sdg-site-starter.git
13
+ git clone https://github.com/open-sdg/open-sdg.git
14
+ # Copy all the theme files into the site starter.
15
+ cp -r open-sdg/_includes/* open-sdg-site-starter/_includes/
16
+ cp -r open-sdg/_layouts/* open-sdg-site-starter/_layouts/
17
+ cp -r open-sdg/_sass/* open-sdg-site-starter/_sass/
18
+ cp -r open-sdg/assets/* open-sdg-site-starter/assets/
19
+ # Copy the required files into the site starter.
20
+ cp tests/_config.yml open-sdg-site-starter/
21
+ cp tests/Gemfile open-sdg-site-starter/
22
+ # Create a symlink to our plugin files.
23
+ ln -s ../lib/jekyll-open-sdg-plugins open-sdg-site-starter/_plugins
24
+ # Install Ruby dependencies.
25
+ cd open-sdg-site-starter && bundle install
26
+
27
+ build:
28
+ cd open-sdg-site-starter && bundle exec jekyll build
29
+
30
+ serve:
31
+ cd open-sdg-site-starter && bundle exec jekyll serve
32
+
33
+ test: install build
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # jekyll-open-sdg-plugins
2
-
3
- > 💎 Jekyll plugins for use with the Open SDG platform
4
-
5
- This plugin provides required Jekyll functionality for the [Open SDG](https://github.com/open-sdg/open-sdg) platform.
6
-
7
- The details on this functionality can be found throughout the [Open SDG documentation](https://open-sdg.readthedocs.io/en/latest/).
1
+ # jekyll-open-sdg-plugins
2
+
3
+ > 💎 Jekyll plugins for use with the Open SDG platform
4
+
5
+ This plugin provides required Jekyll functionality for the [Open SDG](https://github.com/open-sdg/open-sdg) platform.
6
+
7
+ The details on this functionality can be found throughout the [Open SDG documentation](https://open-sdg.readthedocs.io/en/latest/).
@@ -1,18 +1,18 @@
1
- lib = File.expand_path("../lib", __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "jekyll-open-sdg-plugins/version"
4
- Gem::Specification.new do |spec|
5
- spec.name = "jekyll-open-sdg-plugins"
6
- spec.summary = "Jekyll plugins for use with the Open SDG platform"
7
- spec.description = "Jekyll plugins for use with the Open SDG platform"
8
- spec.version = JekyllOpenSdgPlugins::VERSION
9
- spec.authors = ["Brock Fanning"]
10
- spec.email = ["brockfanning@gmail.com"]
11
- spec.homepage = "https://github.com/open-sdg/jekyll-open-sdg-plugins"
12
- spec.licenses = ["MIT"]
13
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
14
- spec.require_paths = ["lib"]
15
- spec.add_dependency "jekyll", "~> 3.0"
16
- spec.add_dependency "deep_merge", "~> 1.2"
17
- spec.add_dependency "json_schemer", "~> 0.2"
18
- end
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "jekyll-open-sdg-plugins/version"
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "jekyll-open-sdg-plugins"
6
+ spec.summary = "Jekyll plugins for use with the Open SDG platform"
7
+ spec.description = "Jekyll plugins for use with the Open SDG platform"
8
+ spec.version = JekyllOpenSdgPlugins::VERSION
9
+ spec.authors = ["Brock Fanning"]
10
+ spec.email = ["brockfanning@gmail.com"]
11
+ spec.homepage = "https://github.com/open-sdg/jekyll-open-sdg-plugins"
12
+ spec.licenses = ["MIT"]
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
14
+ spec.require_paths = ["lib"]
15
+ spec.add_dependency "jekyll", "~> 3.0"
16
+ spec.add_dependency "deep_merge", "~> 1.2"
17
+ spec.add_dependency "json_schemer", "~> 0.2"
18
+ end
@@ -1,61 +1,64 @@
1
- require "jekyll"
2
- require_relative "helpers"
3
-
4
- module JekyllOpenSdgPlugins
5
- class BackwardsCompatibility < Jekyll::Generator
6
- safe true
7
- priority :low
8
-
9
- def add_translation_keys(statuses, site)
10
- statuses.each do |status|
11
- status_var = 'value'
12
- unless status.has_key?(status_var)
13
- status_var = 'status'
14
- end
15
- status_in_site_config = site.config['reporting_status']['status_types'].detect {|s| s['value'] == status[status_var] }
16
- if status_in_site_config.nil?
17
- opensdg_notice('Unexpected reporting status type: ' + status[status_var] + '. Expected reporting status types:')
18
- puts site.config['reporting_status']['status_types'].map { |s| s['value'] }
19
- end
20
- status['translation_key'] = status_in_site_config['label']
21
- end
22
- end
23
-
24
- # This file is used to avoid any backwards compatibility issues
25
- # as the Open SDG API changes over time.
26
- def generate(site)
27
-
28
- # Handle legacy treatment of reporting status types.
29
- unless (site.config.has_key?('reporting_status') &&
30
- site.config['reporting_status'].has_key?('status_types') &&
31
- site.config['reporting_status']['status_types'].count > 0)
32
- reporting_status = site.data['schema'].detect {|f| f['name'] == 'reporting_status' }
33
- reporting_status_types = reporting_status['field']['options']
34
- site.config['reporting_status']['status_types'] = reporting_status_types.map do |status_type|
35
- {
36
- 'value' => status_type['value'],
37
- 'label' => status_type['translation_key'],
38
- }
39
- end
40
- end
41
-
42
- # Also fill in the "reporting" data with things needed by older templates.
43
- add_translation_keys(site.data['reporting']['statuses'], site)
44
- add_translation_keys(site.data['reporting']['overall']['statuses'], site)
45
-
46
- if site.data['reporting'].has_key?('extra_fields')
47
- site.data['reporting']['extra_fields'].each do |key, extra_field|
48
- extra_field.each do |extra_field_value|
49
- add_translation_keys(extra_field_value['statuses'], site)
50
- end
51
- end
52
- end
53
-
54
- if site.data['reporting'].has_key?('goals')
55
- site.data['reporting']['goals'].each do |goal|
56
- add_translation_keys(goal['statuses'], site)
57
- end
58
- end
59
- end
60
- end
61
- end
1
+ require "jekyll"
2
+ require_relative "helpers"
3
+
4
+ module JekyllOpenSdgPlugins
5
+ class BackwardsCompatibility < Jekyll::Generator
6
+ safe true
7
+ priority :low
8
+
9
+ def add_translation_keys(statuses, site)
10
+ statuses.each do |status|
11
+ status_var = 'value'
12
+ unless status.has_key?(status_var)
13
+ status_var = 'status'
14
+ end
15
+ status_in_site_config = site.config['reporting_status']['status_types'].detect {|s| s['value'] == status[status_var] }
16
+ if status_in_site_config.nil?
17
+ opensdg_notice('Unexpected reporting status type: ' + status[status_var] + '. Expected reporting status types:')
18
+ puts site.config['reporting_status']['status_types'].map { |s| s['value'] }
19
+ end
20
+ status['translation_key'] = status_in_site_config['label']
21
+ end
22
+ end
23
+
24
+ # This file is used to avoid any backwards compatibility issues
25
+ # as the Open SDG API changes over time.
26
+ def generate(site)
27
+
28
+ # Handle legacy treatment of reporting status types.
29
+ unless (site.config.has_key?('reporting_status') &&
30
+ site.config['reporting_status'].has_key?('status_types') &&
31
+ site.config['reporting_status']['status_types'].count > 0)
32
+ reporting_status = site.data['schema'].detect {|f| f['name'] == 'reporting_status' }
33
+ reporting_status_types = reporting_status['field']['options']
34
+ unless site.config.has_key?('reporting_status')
35
+ site.config['reporting_status'] = {}
36
+ end
37
+ site.config['reporting_status']['status_types'] = reporting_status_types.map do |status_type|
38
+ {
39
+ 'value' => status_type['value'],
40
+ 'label' => status_type['translation_key'],
41
+ }
42
+ end
43
+ end
44
+
45
+ # Also fill in the "reporting" data with things needed by older templates.
46
+ add_translation_keys(site.data['reporting']['statuses'], site)
47
+ add_translation_keys(site.data['reporting']['overall']['statuses'], site)
48
+
49
+ if site.data['reporting'].has_key?('extra_fields')
50
+ site.data['reporting']['extra_fields'].each do |key, extra_field|
51
+ extra_field.each do |extra_field_value|
52
+ add_translation_keys(extra_field_value['statuses'], site)
53
+ end
54
+ end
55
+ end
56
+
57
+ if site.data['reporting'].has_key?('goals')
58
+ site.data['reporting']['goals'].each do |goal|
59
+ add_translation_keys(goal['statuses'], site)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,85 +1,85 @@
1
- require "jekyll"
2
- require_relative "helpers"
3
-
4
- module JekyllOpenSdgPlugins
5
- class CreateGoals < Jekyll::Generator
6
- safe true
7
- priority :normal
8
-
9
- def generate(site)
10
- # If site.create_goals is set, create goals per the metadata.
11
- if site.config['languages'] and site.config['create_goals'] and site.config['create_goals'].key?('layout') and site.config['create_goals']['layout'] != ''
12
- # Compile the list of goals.
13
- goals = {}
14
- # Are we using translated builds?
15
- metadata = {}
16
- if opensdg_translated_builds(site)
17
- # If we are using translated builds, the 'meta' data is underneath
18
- # language codes. We just use the first language.
19
- default_language = site.config['languages'][0]
20
- metadata = site.data[default_language]['meta']
21
- else
22
- # Otherwise the 'meta' data is not underneath any language code.
23
- metadata = site.data['meta']
24
- end
25
- metadata.each do |inid, indicator|
26
- if indicator.has_key?('standalone') and indicator['standalone']
27
- next
28
- end
29
- goal = inid.split('-')[0]
30
- goals[goal] = true
31
- end
32
- # Decide what layout to use for the goal pages.
33
- layout = site.config['create_goals']['layout']
34
- # See if we need to "map" any language codes.
35
- languages_public = Hash.new
36
- if site.config['languages_public']
37
- languages_public = opensdg_languages_public(site)
38
- end
39
- # Loop through the languages.
40
- site.config['languages'].each_with_index do |language, index|
41
- # Get the "public language" (for URLs) which may be different.
42
- language_public = language
43
- if languages_public[language]
44
- language_public = languages_public[language]
45
- end
46
- # Loop through the goals.
47
- goal_index = 0
48
- goals.keys.sort.each do |goal|
49
- # Add the language subfolder for all except the default (first) language.
50
- dir = index == 0 ? goal.to_s : File.join(language_public, goal.to_s)
51
- # Create the goal page.
52
- site.collections['goals'].docs << GoalPage.new(site, site.source, dir, goal, language, layout, goal_index)
53
- goal_index += 1
54
- end
55
- end
56
- end
57
- end
58
- end
59
-
60
- # A Page subclass used in the `CreateGoals` class.
61
- class GoalPage < Jekyll::Page
62
- def initialize(site, base, dir, goal, language, layout, goal_index)
63
- @site = site
64
- @base = base
65
- @dir = dir
66
- @name = 'index.html'
67
-
68
- goal_content = ''
69
- if site.config['create_goals'].has_key?('goals')
70
- if !site.config['create_goals']['goals'][goal_index].nil?
71
- goal_content = site.config['create_goals']['goals'][goal_index]['content']
72
- end
73
- end
74
- @content = goal_content
75
-
76
- self.process(@name)
77
- self.data = {}
78
- self.data['goal_number'] = goal.to_s
79
- self.data['language'] = language
80
- self.data['layout'] = layout
81
- # Backwards compatibility:
82
- self.data['sdg_goal'] = self.data['goal_number']
83
- end
84
- end
85
- end
1
+ require "jekyll"
2
+ require_relative "helpers"
3
+
4
+ module JekyllOpenSdgPlugins
5
+ class CreateGoals < Jekyll::Generator
6
+ safe true
7
+ priority :normal
8
+
9
+ def generate(site)
10
+ # If site.create_goals is set, create goals per the metadata.
11
+ if site.config['languages'] and site.config['create_goals'] and site.config['create_goals'].key?('layout') and site.config['create_goals']['layout'] != ''
12
+ # Compile the list of goals.
13
+ goals = {}
14
+ # Are we using translated builds?
15
+ metadata = {}
16
+ if opensdg_translated_builds(site)
17
+ # If we are using translated builds, the 'meta' data is underneath
18
+ # language codes. We just use the first language.
19
+ default_language = site.config['languages'][0]
20
+ metadata = site.data[default_language]['meta']
21
+ else
22
+ # Otherwise the 'meta' data is not underneath any language code.
23
+ metadata = site.data['meta']
24
+ end
25
+ metadata.each do |inid, indicator|
26
+ if indicator.has_key?('standalone') and indicator['standalone']
27
+ next
28
+ end
29
+ goal = inid.split('-')[0]
30
+ goals[goal] = true
31
+ end
32
+ # Decide what layout to use for the goal pages.
33
+ layout = site.config['create_goals']['layout']
34
+ # See if we need to "map" any language codes.
35
+ languages_public = Hash.new
36
+ if site.config['languages_public']
37
+ languages_public = opensdg_languages_public(site)
38
+ end
39
+ # Loop through the languages.
40
+ site.config['languages'].each_with_index do |language, index|
41
+ # Get the "public language" (for URLs) which may be different.
42
+ language_public = language
43
+ if languages_public[language]
44
+ language_public = languages_public[language]
45
+ end
46
+ # Loop through the goals.
47
+ goal_index = 0
48
+ goals.keys.sort.each do |goal|
49
+ # Add the language subfolder for all except the default (first) language.
50
+ dir = index == 0 ? goal.to_s : File.join(language_public, goal.to_s)
51
+ # Create the goal page.
52
+ site.collections['goals'].docs << GoalPage.new(site, site.source, dir, goal, language, layout, goal_index)
53
+ goal_index += 1
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ # A Page subclass used in the `CreateGoals` class.
61
+ class GoalPage < Jekyll::Page
62
+ def initialize(site, base, dir, goal, language, layout, goal_index)
63
+ @site = site
64
+ @base = base
65
+ @dir = dir
66
+ @name = 'index.html'
67
+
68
+ goal_content = ''
69
+ if site.config['create_goals'].has_key?('goals')
70
+ if !site.config['create_goals']['goals'][goal_index].nil?
71
+ goal_content = site.config['create_goals']['goals'][goal_index]['content']
72
+ end
73
+ end
74
+ @content = goal_content
75
+
76
+ self.process(@name)
77
+ self.data = {}
78
+ self.data['goal_number'] = goal.to_s
79
+ self.data['language'] = language
80
+ self.data['layout'] = layout
81
+ # Backwards compatibility:
82
+ self.data['sdg_goal'] = self.data['goal_number']
83
+ end
84
+ end
85
+ end