jekyll-open-sdg-plugins 1.0.0.rc22 → 1.2.0.pre.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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)
@@ -0,0 +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
@@ -0,0 +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,3 +1,3 @@
1
- module JekyllOpenSdgPlugins
2
- VERSION = "1.0.0.rc22".freeze
3
- end
1
+ module JekyllOpenSdgPlugins
2
+ VERSION = "1.2.0-beta2".freeze
3
+ end
@@ -0,0 +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"
@@ -0,0 +1,147 @@
1
+ # Jekyll configuration for Open SDG platform
2
+
3
+ validate_site_config: true
4
+ validate_indicator_config: true
5
+
6
+ baseurl: "/open-sdg-site-starter"
7
+ remote_data_prefix: "https://open-sdg.org/open-sdg-data-starter"
8
+ data_edit_url: http://prose.io/#open-sdg/open-sdg-data-starter/edit/develop/data/indicator_[id].csv
9
+ metadata_edit_url: http://prose.io/#open-sdg/open-sdg-data-starter/edit/develop/meta/[id].md
10
+ languages:
11
+ - en
12
+
13
+ title: Indicators For The Sustainable Development Goals
14
+ url: ""
15
+ data_dir: data
16
+ environment: staging
17
+
18
+ create_indicators:
19
+ layout: indicator
20
+ create_goals:
21
+ layout: goal-by-target-vertical
22
+ create_pages:
23
+ - folder: /
24
+ layout: frontpage-alt
25
+ - folder: /goals
26
+ layout: goals
27
+ - folder: /reporting-status
28
+ layout: reportingstatus
29
+ - filename: indicators.json
30
+ folder: /
31
+ layout: indicator-json
32
+ - folder: /search
33
+ layout: search
34
+
35
+ analytics:
36
+ ga_prod: ''
37
+
38
+ # Replace the email addresses below.
39
+ email_contacts:
40
+ questions: test@example.com
41
+ suggestions: test@example.com
42
+ functional: test@example.com
43
+
44
+ # International Support
45
+ # Eg name: Australia and adjective: Australian
46
+ country:
47
+ name: Australia
48
+ adjective: Australian
49
+
50
+ # Optionally set a title/body for the frontpage banner. The defaults below point to a standard
51
+ # translation, but feel free to change it as needed.
52
+ frontpage_introduction_banner:
53
+ title: frontpage.intro_title
54
+ description: frontpage.intro_body
55
+
56
+ frontpage_goals_grid:
57
+ title: Our data for Sustainable Development Goal indicators
58
+ description: Click on each goal for our Sustainable Development Goal global indicator data.
59
+
60
+ frontpage_cards:
61
+ - title: frontpage.download_all
62
+ include: components/download-all-data.html
63
+ - title: Lorem ipsum
64
+ content: |
65
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi mollis
66
+ cursus est sed dapibus.
67
+ button_label: Read more
68
+ button_link: https://example.com
69
+ - title: Nam vestibulum
70
+ content: |
71
+ Nam vestibulum, purus quis porttitor imperdiet, nisl sem mollis nisl, a
72
+ interdum risus enim vitae tortor. Donec feugiat accumsan rutrum.
73
+ button_label: Read more
74
+ button_link: https://example.com
75
+
76
+ # Pages
77
+ collections:
78
+ pages:
79
+ output: true
80
+ permalink: /:path/
81
+ posts:
82
+ output: true
83
+ permalink: /news/:year/:month/:day/:title.html
84
+ indicators:
85
+ output: true
86
+ goals:
87
+ output: true
88
+
89
+ # Menu
90
+ menu:
91
+ # Use these to customise the main navigation.
92
+ - path: /goals
93
+ # The "translation_key" refers to the key in the SDG Translations repository.
94
+ translation_key: general.goals
95
+ - path: /reporting-status
96
+ translation_key: menu.reporting_status
97
+ - path: /about
98
+ translation_key: menu.about
99
+ - path: /guidance
100
+ translation_key: menu.guidance
101
+ - path: /faq
102
+ translation_key: menu.faq
103
+ - path: /news
104
+ translation_key: menu.updates
105
+
106
+ footer_menu:
107
+ - path: mailto:my-email-address@example.com
108
+ translation_key: menu.contact_us
109
+ - path: https://twitter.com/MyTwitterAccount
110
+ translation_key: general.twitter
111
+ - path: https://facebook.com/MyFacebookAccount
112
+ translation_key: general.facebook
113
+ - path: /about/cookies-and-privacy/
114
+ translation_key: menu.cookies
115
+
116
+ # Configure the text (or "translation key") to be used on the
117
+ # non-global metadata tab.
118
+ non_global_metadata: indicator.national_metadata
119
+
120
+ # Set a base for all goal image URLs. Note that the full goal image path will be
121
+ # the base below, completed with: /[language]/[number].png (eg, /fr/6.png).
122
+ goal_image_base: https://open-sdg.org/sdg-translations/assets/img/goals
123
+
124
+ # Exclude some files/folders.
125
+ exclude:
126
+ - vendor
127
+ - scripts
128
+ - remotedata
129
+ - Gemfile
130
+ - Gemfile.lock
131
+ - README
132
+ - README.md
133
+ - LICENSE
134
+
135
+ # Optionally uncomment and update the settings below to control the mapping functionality.
136
+ # These are only a few of the possible settings. For more details, see:
137
+ # https://open-sdg.readthedocs.io/en/latest/maps/
138
+ #map_options:
139
+ # minZoom: 5
140
+ # tileURL: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
141
+ # tileOptions:
142
+ # attribution: 'My map attribution'
143
+ #map_layers:
144
+ # - min_zoom: 5
145
+ # max_zoom: 10
146
+ # subfolder: my-geojson-subfolder
147
+ # label: My map layer label (can be a translation key)