jekyll-open-sdg-plugins 1.6.1 → 1.7.0.pre.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +64 -64
- data/lib/jekyll-open-sdg-plugins/create_goals.rb +85 -85
- data/lib/jekyll-open-sdg-plugins/create_indicators.rb +206 -206
- data/lib/jekyll-open-sdg-plugins/create_pages.rb +135 -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 +1652 -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 +73 -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,111 +1,111 @@
|
|
1
|
-
require "jekyll"
|
2
|
-
require_relative "helpers"
|
3
|
-
|
4
|
-
module Jekyll
|
5
|
-
module TranslateMetadataField
|
6
|
-
# Takes a metadata field (machine name) and returns a translated string
|
7
|
-
# according to the language of the current page, suitable for displaying to
|
8
|
-
# the public. It gets this string by looking in the site's "schema" for a
|
9
|
-
# "translation_key" property, and running that through the
|
10
|
-
# opensdg_translate_key() helper function.
|
11
|
-
#
|
12
|
-
# Temporary backwards compatibility: If the check fails, it falls back to
|
13
|
-
# checking for a translation in the 'metadata_fields' translation group.
|
14
|
-
#
|
15
|
-
# More backwards compatibility: If all of the above fails, it falls back to
|
16
|
-
# using whatever is in a "label" property in the schema.
|
17
|
-
#
|
18
|
-
# Parameters
|
19
|
-
# ----------
|
20
|
-
# field_name : string
|
21
|
-
# The machine name of a metadata field.
|
22
|
-
def translate_metadata_field(field_name)
|
23
|
-
|
24
|
-
# Determine the language of the current page.
|
25
|
-
t = @context.registers[:site].data['translations']
|
26
|
-
lang = @context.environments.first['page']['language']
|
27
|
-
# Get the schema.
|
28
|
-
schema = @context.registers[:site].data['schema']
|
29
|
-
|
30
|
-
# Find the field.
|
31
|
-
field = schema.select {|x| x['name'] == field_name }
|
32
|
-
if field
|
33
|
-
field = field.first()
|
34
|
-
end
|
35
|
-
|
36
|
-
to_translate = ''
|
37
|
-
# First choice - use the 'translation_key' property from the schema.
|
38
|
-
if field && field['field'].has_key?('translation_key')
|
39
|
-
to_translate = field['field']['translation_key']
|
40
|
-
# Next choice - try the 'metadata_fields' translation group.
|
41
|
-
elsif t[lang].has_key?('metadata_fields') && t[lang]['metadata_fields'].has_key?(field_name)
|
42
|
-
to_translate = 'metadata_fields.' + field_name
|
43
|
-
# Next choice - use the 'label' from the schema.
|
44
|
-
elsif field && field['field'].has_key?('label')
|
45
|
-
to_translate = field['field']['label']
|
46
|
-
# Last choice - just use the field name.
|
47
|
-
else
|
48
|
-
to_translate = field_name
|
49
|
-
end
|
50
|
-
|
51
|
-
return opensdg_translate_key(to_translate, t, lang)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
module TranslateMetadataFieldOption
|
56
|
-
# Takes a metadata field (machine name) and option (value) and returns a
|
57
|
-
# translated string according to the language of the current page, suitable
|
58
|
-
# for displaying to the public.
|
59
|
-
#
|
60
|
-
# By contrast to TranslateMetadataField above, this is for translating the
|
61
|
-
# options of multiple-choice schema fields. But similar to
|
62
|
-
# TranslateMetadataField, this looks for a "translation_key" property on
|
63
|
-
# the option in the schema.
|
64
|
-
#
|
65
|
-
# Temporary backwards compatibility: If the check fails, it falls back to
|
66
|
-
# whatever is in a "name" property in the schema.
|
67
|
-
#
|
68
|
-
# Parameters
|
69
|
-
# ----------
|
70
|
-
# field_name : string
|
71
|
-
# The machine name of a metadata field.
|
72
|
-
# value : string
|
73
|
-
# The 'value' of the option to use.
|
74
|
-
def translate_metadata_field_option(field_name, value)
|
75
|
-
|
76
|
-
# Determine the language of the current page.
|
77
|
-
t = @context.registers[:site].data['translations']
|
78
|
-
lang = @context.environments.first['page']['language']
|
79
|
-
# Get the schema.
|
80
|
-
schema = @context.registers[:site].data['schema']
|
81
|
-
|
82
|
-
# Find the field.
|
83
|
-
field = schema.select {|x| x['name'] == field_name}
|
84
|
-
if field
|
85
|
-
field = field.first()
|
86
|
-
end
|
87
|
-
|
88
|
-
# Fall back to the value itself.
|
89
|
-
to_translate = value
|
90
|
-
|
91
|
-
# Look for the 'translation_key' property from the schema.
|
92
|
-
if field && field['field'].has_key?('options')
|
93
|
-
option = field['field']['options'].select {|x| x['value'] == value}
|
94
|
-
if option
|
95
|
-
option = option.first()
|
96
|
-
if option.has_key?('translation_key')
|
97
|
-
to_translate = option['translation_key']
|
98
|
-
else
|
99
|
-
to_translate = option['name']
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
return opensdg_translate_key(to_translate, t, lang)
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
Liquid::Template.register_filter(Jekyll::TranslateMetadataField)
|
111
|
-
Liquid::Template.register_filter(Jekyll::TranslateMetadataFieldOption)
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "helpers"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
module TranslateMetadataField
|
6
|
+
# Takes a metadata field (machine name) and returns a translated string
|
7
|
+
# according to the language of the current page, suitable for displaying to
|
8
|
+
# the public. It gets this string by looking in the site's "schema" for a
|
9
|
+
# "translation_key" property, and running that through the
|
10
|
+
# opensdg_translate_key() helper function.
|
11
|
+
#
|
12
|
+
# Temporary backwards compatibility: If the check fails, it falls back to
|
13
|
+
# checking for a translation in the 'metadata_fields' translation group.
|
14
|
+
#
|
15
|
+
# More backwards compatibility: If all of the above fails, it falls back to
|
16
|
+
# using whatever is in a "label" property in the schema.
|
17
|
+
#
|
18
|
+
# Parameters
|
19
|
+
# ----------
|
20
|
+
# field_name : string
|
21
|
+
# The machine name of a metadata field.
|
22
|
+
def translate_metadata_field(field_name)
|
23
|
+
|
24
|
+
# Determine the language of the current page.
|
25
|
+
t = @context.registers[:site].data['translations']
|
26
|
+
lang = @context.environments.first['page']['language']
|
27
|
+
# Get the schema.
|
28
|
+
schema = @context.registers[:site].data['schema']
|
29
|
+
|
30
|
+
# Find the field.
|
31
|
+
field = schema.select {|x| x['name'] == field_name }
|
32
|
+
if field
|
33
|
+
field = field.first()
|
34
|
+
end
|
35
|
+
|
36
|
+
to_translate = ''
|
37
|
+
# First choice - use the 'translation_key' property from the schema.
|
38
|
+
if field && field['field'].has_key?('translation_key')
|
39
|
+
to_translate = field['field']['translation_key']
|
40
|
+
# Next choice - try the 'metadata_fields' translation group.
|
41
|
+
elsif t[lang].has_key?('metadata_fields') && t[lang]['metadata_fields'].has_key?(field_name)
|
42
|
+
to_translate = 'metadata_fields.' + field_name
|
43
|
+
# Next choice - use the 'label' from the schema.
|
44
|
+
elsif field && field['field'].has_key?('label')
|
45
|
+
to_translate = field['field']['label']
|
46
|
+
# Last choice - just use the field name.
|
47
|
+
else
|
48
|
+
to_translate = field_name
|
49
|
+
end
|
50
|
+
|
51
|
+
return opensdg_translate_key(to_translate, t, lang)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module TranslateMetadataFieldOption
|
56
|
+
# Takes a metadata field (machine name) and option (value) and returns a
|
57
|
+
# translated string according to the language of the current page, suitable
|
58
|
+
# for displaying to the public.
|
59
|
+
#
|
60
|
+
# By contrast to TranslateMetadataField above, this is for translating the
|
61
|
+
# options of multiple-choice schema fields. But similar to
|
62
|
+
# TranslateMetadataField, this looks for a "translation_key" property on
|
63
|
+
# the option in the schema.
|
64
|
+
#
|
65
|
+
# Temporary backwards compatibility: If the check fails, it falls back to
|
66
|
+
# whatever is in a "name" property in the schema.
|
67
|
+
#
|
68
|
+
# Parameters
|
69
|
+
# ----------
|
70
|
+
# field_name : string
|
71
|
+
# The machine name of a metadata field.
|
72
|
+
# value : string
|
73
|
+
# The 'value' of the option to use.
|
74
|
+
def translate_metadata_field_option(field_name, value)
|
75
|
+
|
76
|
+
# Determine the language of the current page.
|
77
|
+
t = @context.registers[:site].data['translations']
|
78
|
+
lang = @context.environments.first['page']['language']
|
79
|
+
# Get the schema.
|
80
|
+
schema = @context.registers[:site].data['schema']
|
81
|
+
|
82
|
+
# Find the field.
|
83
|
+
field = schema.select {|x| x['name'] == field_name}
|
84
|
+
if field
|
85
|
+
field = field.first()
|
86
|
+
end
|
87
|
+
|
88
|
+
# Fall back to the value itself.
|
89
|
+
to_translate = value
|
90
|
+
|
91
|
+
# Look for the 'translation_key' property from the schema.
|
92
|
+
if field && field['field'].has_key?('options')
|
93
|
+
option = field['field']['options'].select {|x| x['value'] == value}
|
94
|
+
if option
|
95
|
+
option = option.first()
|
96
|
+
if option.has_key?('translation_key')
|
97
|
+
to_translate = option['translation_key']
|
98
|
+
else
|
99
|
+
to_translate = option['name']
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
return opensdg_translate_key(to_translate, t, lang)
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
Liquid::Template.register_filter(Jekyll::TranslateMetadataField)
|
111
|
+
Liquid::Template.register_filter(Jekyll::TranslateMetadataFieldOption)
|
@@ -1,52 +1,52 @@
|
|
1
|
-
require "jekyll"
|
2
|
-
require_relative "helpers"
|
3
|
-
require "json"
|
4
|
-
require "json_schemer"
|
5
|
-
|
6
|
-
module JekyllOpenSdgPlugins
|
7
|
-
class ValidateIndicatorConfig < Jekyll::Generator
|
8
|
-
safe true
|
9
|
-
priority :lowest
|
10
|
-
|
11
|
-
def generate(site)
|
12
|
-
|
13
|
-
schema_path = File.join(File.dirname(__FILE__), 'schema-indicator-config.json')
|
14
|
-
json_from_file = File.read(schema_path)
|
15
|
-
schema = JSON.parse(json_from_file)
|
16
|
-
schemer = JSONSchemer.schema(schema)
|
17
|
-
|
18
|
-
# Perform validation if the "validate_indicator_config" flag is true.
|
19
|
-
if site.config.has_key?('validate_indicator_config') && site.config['validate_indicator_config']
|
20
|
-
# We don't care too much what language we use, just get the first one.
|
21
|
-
language = 'en'
|
22
|
-
if site.config.has_key?('languages')
|
23
|
-
language = site.config['languages'][0]
|
24
|
-
end
|
25
|
-
metadata = {}
|
26
|
-
if opensdg_translated_builds(site)
|
27
|
-
metadata = site.data[language]['meta']
|
28
|
-
else
|
29
|
-
metadata = site.data['meta']
|
30
|
-
end
|
31
|
-
# Loop through the indicators (using metadata as a list).
|
32
|
-
validation_failed = false
|
33
|
-
metadata.each do |inid, meta|
|
34
|
-
unless schemer.valid?(meta)
|
35
|
-
validation_failed = true
|
36
|
-
opensdg_notice('Indicator ' + inid + ' configuration invalid:')
|
37
|
-
errors = schemer.validate(meta).to_a
|
38
|
-
errors.each { |error| opensdg_validation_error(error) }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
if validation_failed
|
42
|
-
opensdg_notice "Some indicator configuration was not valid. See feedback above."
|
43
|
-
raise "Invalid indicator configuration"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Regardless place the schema in site data so it can be used in Jekyll templates.
|
48
|
-
site.data['schema-indicator-config'] = schema
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "helpers"
|
3
|
+
require "json"
|
4
|
+
require "json_schemer"
|
5
|
+
|
6
|
+
module JekyllOpenSdgPlugins
|
7
|
+
class ValidateIndicatorConfig < Jekyll::Generator
|
8
|
+
safe true
|
9
|
+
priority :lowest
|
10
|
+
|
11
|
+
def generate(site)
|
12
|
+
|
13
|
+
schema_path = File.join(File.dirname(__FILE__), 'schema-indicator-config.json')
|
14
|
+
json_from_file = File.read(schema_path)
|
15
|
+
schema = JSON.parse(json_from_file)
|
16
|
+
schemer = JSONSchemer.schema(schema)
|
17
|
+
|
18
|
+
# Perform validation if the "validate_indicator_config" flag is true.
|
19
|
+
if site.config.has_key?('validate_indicator_config') && site.config['validate_indicator_config']
|
20
|
+
# We don't care too much what language we use, just get the first one.
|
21
|
+
language = 'en'
|
22
|
+
if site.config.has_key?('languages')
|
23
|
+
language = site.config['languages'][0]
|
24
|
+
end
|
25
|
+
metadata = {}
|
26
|
+
if opensdg_translated_builds(site)
|
27
|
+
metadata = site.data[language]['meta']
|
28
|
+
else
|
29
|
+
metadata = site.data['meta']
|
30
|
+
end
|
31
|
+
# Loop through the indicators (using metadata as a list).
|
32
|
+
validation_failed = false
|
33
|
+
metadata.each do |inid, meta|
|
34
|
+
unless schemer.valid?(meta)
|
35
|
+
validation_failed = true
|
36
|
+
opensdg_notice('Indicator ' + inid + ' configuration invalid:')
|
37
|
+
errors = schemer.validate(meta).to_a
|
38
|
+
errors.each { |error| opensdg_validation_error(error) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
if validation_failed
|
42
|
+
opensdg_notice "Some indicator configuration was not valid. See feedback above."
|
43
|
+
raise "Invalid indicator configuration"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Regardless place the schema in site data so it can be used in Jekyll templates.
|
48
|
+
site.data['schema-indicator-config'] = schema
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
require "jekyll"
|
2
|
-
require_relative "helpers"
|
3
|
-
require "json"
|
4
|
-
require "json_schemer"
|
5
|
-
|
6
|
-
module JekyllOpenSdgPlugins
|
7
|
-
class ValidateSiteConfig < Jekyll::Generator
|
8
|
-
safe true
|
9
|
-
priority :highest
|
10
|
-
|
11
|
-
def generate(site)
|
12
|
-
|
13
|
-
schema_path = File.join(File.dirname(__FILE__), 'schema-site-config.json')
|
14
|
-
json_from_file = File.read(schema_path)
|
15
|
-
schema = JSON.parse(json_from_file)
|
16
|
-
schemer = JSONSchemer.schema(schema)
|
17
|
-
|
18
|
-
# Perform validation if the "validate_site_config" flag is true.
|
19
|
-
if site.config.has_key?('validate_site_config') && site.config['validate_site_config']
|
20
|
-
unless schemer.valid?(site.config)
|
21
|
-
opensdg_notice('Site configuration invalid:')
|
22
|
-
errors = schemer.validate(site.config).to_a
|
23
|
-
errors.each { |error| opensdg_validation_error(error) }
|
24
|
-
opensdg_notice "The site configuration is not valid. See feedback above."
|
25
|
-
raise "Invalid site configuration"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Regardless place the schema in site data so it can be used in Jekyll templates.
|
30
|
-
site.data['schema-site-config'] = schema
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "helpers"
|
3
|
+
require "json"
|
4
|
+
require "json_schemer"
|
5
|
+
|
6
|
+
module JekyllOpenSdgPlugins
|
7
|
+
class ValidateSiteConfig < Jekyll::Generator
|
8
|
+
safe true
|
9
|
+
priority :highest
|
10
|
+
|
11
|
+
def generate(site)
|
12
|
+
|
13
|
+
schema_path = File.join(File.dirname(__FILE__), 'schema-site-config.json')
|
14
|
+
json_from_file = File.read(schema_path)
|
15
|
+
schema = JSON.parse(json_from_file)
|
16
|
+
schemer = JSONSchemer.schema(schema)
|
17
|
+
|
18
|
+
# Perform validation if the "validate_site_config" flag is true.
|
19
|
+
if site.config.has_key?('validate_site_config') && site.config['validate_site_config']
|
20
|
+
unless schemer.valid?(site.config)
|
21
|
+
opensdg_notice('Site configuration invalid:')
|
22
|
+
errors = schemer.validate(site.config).to_a
|
23
|
+
errors.each { |error| opensdg_validation_error(error) }
|
24
|
+
opensdg_notice "The site configuration is not valid. See feedback above."
|
25
|
+
raise "Invalid site configuration"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Regardless place the schema in site data so it can be used in Jekyll templates.
|
30
|
+
site.data['schema-site-config'] = schema
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module JekyllOpenSdgPlugins
|
2
|
-
VERSION = "1.
|
3
|
-
end
|
1
|
+
module JekyllOpenSdgPlugins
|
2
|
+
VERSION = "1.7.0-beta1".freeze
|
3
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require_relative "jekyll-open-sdg-plugins/version"
|
2
|
-
require_relative "jekyll-open-sdg-plugins/site_configuration"
|
3
|
-
require_relative "jekyll-open-sdg-plugins/validate_site_config"
|
4
|
-
require_relative "jekyll-open-sdg-plugins/fetch_remote_data"
|
5
|
-
require_relative "jekyll-open-sdg-plugins/translate_key"
|
6
|
-
require_relative "jekyll-open-sdg-plugins/translate_date"
|
7
|
-
require_relative "jekyll-open-sdg-plugins/translate_metadata_field"
|
8
|
-
require_relative "jekyll-open-sdg-plugins/create_indicators"
|
9
|
-
require_relative "jekyll-open-sdg-plugins/create_goals"
|
10
|
-
require_relative "jekyll-open-sdg-plugins/create_pages"
|
11
|
-
require_relative "jekyll-open-sdg-plugins/sdg_variables"
|
12
|
-
require_relative "jekyll-open-sdg-plugins/search_index"
|
13
|
-
require_relative "jekyll-open-sdg-plugins/validate_indicator_config"
|
14
|
-
require_relative "jekyll-open-sdg-plugins/metadata_schema_to_config"
|
15
|
-
require_relative "jekyll-open-sdg-plugins/backwards_compatibility"
|
16
|
-
|
17
|
-
module JekyllOpenSdgPlugins
|
18
|
-
end
|
1
|
+
require_relative "jekyll-open-sdg-plugins/version"
|
2
|
+
require_relative "jekyll-open-sdg-plugins/site_configuration"
|
3
|
+
require_relative "jekyll-open-sdg-plugins/validate_site_config"
|
4
|
+
require_relative "jekyll-open-sdg-plugins/fetch_remote_data"
|
5
|
+
require_relative "jekyll-open-sdg-plugins/translate_key"
|
6
|
+
require_relative "jekyll-open-sdg-plugins/translate_date"
|
7
|
+
require_relative "jekyll-open-sdg-plugins/translate_metadata_field"
|
8
|
+
require_relative "jekyll-open-sdg-plugins/create_indicators"
|
9
|
+
require_relative "jekyll-open-sdg-plugins/create_goals"
|
10
|
+
require_relative "jekyll-open-sdg-plugins/create_pages"
|
11
|
+
require_relative "jekyll-open-sdg-plugins/sdg_variables"
|
12
|
+
require_relative "jekyll-open-sdg-plugins/search_index"
|
13
|
+
require_relative "jekyll-open-sdg-plugins/validate_indicator_config"
|
14
|
+
require_relative "jekyll-open-sdg-plugins/metadata_schema_to_config"
|
15
|
+
require_relative "jekyll-open-sdg-plugins/backwards_compatibility"
|
16
|
+
|
17
|
+
module JekyllOpenSdgPlugins
|
18
|
+
end
|
data/tests/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
gem "jekyll", "3.8.4"
|
4
|
-
gem "html-proofer"
|
5
|
-
gem "jekyll-remote-theme"
|
6
|
-
gem "deep_merge"
|
7
|
-
gem "json_schemer"
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem "jekyll", "3.8.4"
|
4
|
+
gem "html-proofer"
|
5
|
+
gem "jekyll-remote-theme"
|
6
|
+
gem "deep_merge"
|
7
|
+
gem "json_schemer"
|