jekyll-open-sdg-plugins 1.1.0 → 1.2.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.
@@ -347,9 +347,9 @@ module JekyllOpenSdgPlugins
347
347
  doc.data['t'] = site.data['translations'][language]
348
348
 
349
349
  # Set the remote_data_prefix for this page.
350
- if site.config.has_key? 'remote_data_prefix'
350
+ if site.config.has_key? 'remote_data_prefix' && opensdg_is_path_remote(site.config['remote_data_prefix'])
351
351
  doc.data['remote_data_prefix'] = site.config['remote_data_prefix']
352
- elsif site.config.has_key? 'local_data_folder'
352
+ else
353
353
  doc.data['remote_data_prefix'] = normalize_baseurl(baseurl)
354
354
  end
355
355
  if opensdg_translated_builds(site)
@@ -9,14 +9,18 @@ module JekyllOpenSdgPlugins
9
9
  # relies heavily on the variables created there.
10
10
 
11
11
  # Helper function to prepare content for the search index.
12
- def prepare_content(site, content)
12
+ def prepare_content(site, content, language)
13
13
 
14
14
  # Handle nil content.
15
15
  if !content
16
16
  content = ''
17
17
  end
18
18
 
19
- # First compile any Markdown.
19
+ # Strip whitespace.
20
+ content = content.strip
21
+ # Translate if needed.
22
+ content = opensdg_translate_key(content, site.data['translations'], language)
23
+ # Next compile any Markdown.
20
24
  converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
21
25
  content = converter.convert(content)
22
26
  # Now strip any HTML.
@@ -31,6 +35,10 @@ module JekyllOpenSdgPlugins
31
35
 
32
36
  site.collections.keys.each do |collection|
33
37
  site.collections[collection].docs.each do |doc|
38
+ # Do not index configuration forms.
39
+ if doc.data.has_key?('layout') && doc.data['layout'] == 'config-builder'
40
+ next
41
+ end
34
42
  # We segregate the search items by language.
35
43
  language = doc.data['language']
36
44
  if !search_items.has_key? language
@@ -48,16 +56,17 @@ module JekyllOpenSdgPlugins
48
56
  # The URL of the page.
49
57
  item['url'] = doc.data['indicator']['url']
50
58
  # For the title, use the indicator name.
51
- item['title'] = doc.data['indicator']['name']
59
+ indicator_label = opensdg_translate_key('general.indicator', site.data['translations'], language)
60
+ item['title'] = indicator_label + ' ' + doc.data['indicator']['number'] + ' - ' + doc.data['indicator']['name']
52
61
  # For the content, use the 'page_content' field.
53
- item['content'] = prepare_content(site, doc.data['indicator']['page_content'])
62
+ item['content'] = prepare_content(site, doc.data['indicator']['page_content'], language)
54
63
  # For the id field, use the ID number.
55
64
  item['id'] = doc.data['indicator']['number']
56
65
  # Also index any additional metadata fields.
57
66
  if site.config['search_index_extra_fields']
58
67
  site.config['search_index_extra_fields'].each do |field|
59
68
  if doc.data['indicator'].has_key? field
60
- item[field] = prepare_content(site, doc.data['indicator'][field])
69
+ item[field] = prepare_content(site, doc.data['indicator'][field], language)
61
70
  end
62
71
  end
63
72
  end
@@ -66,7 +75,8 @@ module JekyllOpenSdgPlugins
66
75
  # The URL of the page.
67
76
  item['url'] = doc.data['goal']['url']
68
77
  # For the title we use the goal name.
69
- item['title'] = doc.data['goal']['name']
78
+ goal_label = opensdg_translate_key('general.goal', site.data['translations'], language)
79
+ item['title'] = goal_label + ' ' + doc.data['goal']['number'] + ' - ' + doc.data['goal']['name']
70
80
  # For the content, currently nothing here.
71
81
  item['content'] = ''
72
82
  # For the id field, use the ID number.
@@ -74,8 +84,8 @@ module JekyllOpenSdgPlugins
74
84
  else
75
85
  # Otherwise assume it is a normal Jekyll document.
76
86
  item['url'] = File.join(doc.data['baseurl'], doc.url)
77
- item['title'] = doc.data['title']
78
- item['content'] = prepare_content(site, doc.content)
87
+ item['title'] = prepare_content(site, doc.data['title'], language)
88
+ item['content'] = prepare_content(site, doc.content, language)
79
89
  item['id'] = ''
80
90
  end
81
91
 
@@ -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
1
  module JekyllOpenSdgPlugins
2
- VERSION = "1.1.0".freeze
2
+ VERSION = "1.2.0-beta1".freeze
3
3
  end
@@ -4,3 +4,4 @@ gem "jekyll", "3.8.4"
4
4
  gem "html-proofer"
5
5
  gem "jekyll-remote-theme"
6
6
  gem "deep_merge"
7
+ gem "json_schemer"
@@ -1,5 +1,8 @@
1
1
  # Jekyll configuration for Open SDG platform
2
2
 
3
+ validate_site_config: true
4
+ validate_indicator_config: true
5
+
3
6
  baseurl: "/open-sdg-site-starter"
4
7
  remote_data_prefix: "https://open-sdg.org/open-sdg-data-starter"
5
8
  data_edit_url: http://prose.io/#open-sdg/open-sdg-data-starter/edit/develop/data/indicator_[id].csv
@@ -17,18 +20,17 @@ create_indicators:
17
20
  create_goals:
18
21
  layout: goal-by-target-vertical
19
22
  create_pages:
20
- pages:
21
- - folder: /
22
- layout: frontpage-alt
23
- - folder: /goals
24
- layout: goals
25
- - folder: /reporting-status
26
- layout: reportingstatus
27
- - filename: indicators.json
28
- folder: /
29
- layout: indicator-json
30
- - folder: /search
31
- layout: search
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
32
34
 
33
35
  analytics:
34
36
  ga_prod: ''
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.1.0
4
+ version: 1.2.0.pre.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brock Fanning
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-13 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json_schemer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.2'
41
55
  description: Jekyll plugins for use with the Open SDG platform
42
56
  email:
43
57
  - brockfanning@gmail.com
@@ -58,12 +72,16 @@ files:
58
72
  - lib/jekyll-open-sdg-plugins/create_pages.rb
59
73
  - lib/jekyll-open-sdg-plugins/fetch_remote_data.rb
60
74
  - lib/jekyll-open-sdg-plugins/helpers.rb
75
+ - lib/jekyll-open-sdg-plugins/schema-indicator-config.json
76
+ - lib/jekyll-open-sdg-plugins/schema-site-config.json
61
77
  - lib/jekyll-open-sdg-plugins/sdg_variables.rb
62
78
  - lib/jekyll-open-sdg-plugins/search_index.rb
63
79
  - lib/jekyll-open-sdg-plugins/site_configuration.rb
64
80
  - lib/jekyll-open-sdg-plugins/translate_date.rb
65
81
  - lib/jekyll-open-sdg-plugins/translate_key.rb
66
82
  - lib/jekyll-open-sdg-plugins/translate_metadata_field.rb
83
+ - lib/jekyll-open-sdg-plugins/validate_indicator_config.rb
84
+ - lib/jekyll-open-sdg-plugins/validate_site_config.rb
67
85
  - lib/jekyll-open-sdg-plugins/version.rb
68
86
  - tests/Gemfile
69
87
  - tests/_config.yml
@@ -82,9 +100,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
100
  version: '0'
83
101
  required_rubygems_version: !ruby/object:Gem::Requirement
84
102
  requirements:
85
- - - ">="
103
+ - - ">"
86
104
  - !ruby/object:Gem::Version
87
- version: '0'
105
+ version: 1.3.1
88
106
  requirements: []
89
107
  rubygems_version: 3.1.4
90
108
  signing_key: