jekyll-open-sdg-plugins 0.0.12 → 0.0.13

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: 16c9b1c938fefd342ea55c8ca75b198541d3e5ef00cd785cfbe9251a3d653ced
4
- data.tar.gz: 661807497228354b34eb7f368ad9df48a081a18493663c5621389e62fbf3bb19
3
+ metadata.gz: 2d65f23c1b0dbf8f069a1c0911afc238cf862bb34f0bf70c9aac5031456a1930
4
+ data.tar.gz: 74a2f4592b719e0bd93a0a63db99996e51b8b00c4e2b11758e3eac8bcbd0d045
5
5
  SHA512:
6
- metadata.gz: ee54ba25f833387c4bd61b7c4fda2d24a4722ea3a43664a676e3708c1b81001610f1a8eda3cd0977ab94ce5cfdd407a53586910a6c6a7db7696ec8e04467da5b
7
- data.tar.gz: e59c8876112b4356dc815b0c55195d785c9689ec67e5f2f42e51a6761dd4e40099af1511b2c09e90bdbea9511d1f25465d5de15f3ce62623c17eba67c8e343b9
6
+ metadata.gz: db9402cb822035b8783c2c234b0e0415e9da71c4008e88b6eddec20299327528179ea82b25c588f3f60c4d9069c0ac529878c9292332073417b866b2585bc549
7
+ data.tar.gz: 259cf3566b84dfe25917e187521dda050e24aaaeb1d3db932473e1d96086230c8d4b1e872cb26e0d5b7dcf1ae70ddb30b131c8b583523928e3e14d4b6ca4469d
data/README.md CHANGED
@@ -39,3 +39,35 @@ create_indicators:
39
39
  # This determines which layout is used to render the pages.
40
40
  layout: indicator
41
41
  ```
42
+
43
+ ## 5. Automatically create 4 required pages.
44
+
45
+ This automates the creation of 4 required pages that all implementations of Open SDG will need. These consist of:
46
+
47
+ * the home page: /
48
+ * the indicators json page: /indicators.json
49
+ * the search results page: /search
50
+ * the reporting status page: /reporting-status
51
+
52
+ There are advanced options for overriding the location of these pages (see creae_pages.rb). But see the example below to use the defaults.
53
+
54
+ Usage example (in `_config.yml`):
55
+ ```
56
+ create_pages: true
57
+ ```
58
+
59
+ ## 6. Automatically fetch remote data and translations.
60
+
61
+ This automates the fetching of the remote data (from the "data repository") and any remote translations.
62
+
63
+ Note: This feature is disabled if "jekyll_get_json" is in the site config. This was the older (more verbose) way to do this.
64
+
65
+ Usage example (in `_config.yml`):
66
+ ```
67
+ remote_data_prefix: https://mygithuborg.github.io/my-data-repository
68
+ remote_translations:
69
+ - https://open-sdg.github.io/sdg-translations/translations-0.6.0.json
70
+
71
+ ```
72
+
73
+ For those interested in switching to this convenience feature, note that this makes the "jekyll_get_json" and "remotedatabaseurl" settings obsolete; so they can be removed.
@@ -13,4 +13,5 @@ Gem::Specification.new do |spec|
13
13
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
14
14
  spec.require_paths = ["lib"]
15
15
  spec.add_dependency "jekyll", "~> 3.0"
16
+ spec.add_dependency "deep_merge", "~> 1.2"
16
17
  end
@@ -1,4 +1,5 @@
1
1
  require_relative "jekyll-open-sdg-plugins/version"
2
+ require_relative "jekyll-open-sdg-plugins/fetch_remote_data"
2
3
  require_relative "jekyll-open-sdg-plugins/multilingual_metadata"
3
4
  require_relative "jekyll-open-sdg-plugins/translate_key"
4
5
  require_relative "jekyll-open-sdg-plugins/create_indicators"
@@ -0,0 +1,65 @@
1
+ require "jekyll"
2
+ require 'json'
3
+ require 'deep_merge'
4
+ require 'open-uri'
5
+
6
+ module JekyllOpenSdgPlugins
7
+ class FetchRemoteData < Jekyll::Generator
8
+ safe true
9
+ priority :highest
10
+
11
+ def generate(site)
12
+ # Backwards compatibility - only do this if 'jekyll_get_json' is absent.
13
+ # (This is the older style of remote data fetching.)
14
+ if !site.config['jekyll_get_json']
15
+ # First try to grab the remote data.
16
+ if site.config['remote_data_prefix']
17
+ prefix = site.config['remote_data_prefix']
18
+ # Set the required remotedatabaseurl config setting.
19
+ site.config['remotedatabaseurl'] = prefix
20
+ # Fetch remote data for each of our endpoints.
21
+ endpoints = {
22
+ 'meta' => 'meta/all.json',
23
+ 'headlines' => 'headline/all.json',
24
+ 'schema' => 'meta/schema.json',
25
+ 'reporting' => 'stats/reporting.json'
26
+ }
27
+ endpoints.each do |key, value|
28
+ target = site.data[key]
29
+ endpoint = prefix + '/' + value
30
+ begin
31
+ source = JSON.load(open(endpoint))
32
+ if target
33
+ target.deep_merge(source)
34
+ else
35
+ site.data[key] = source
36
+ end
37
+ rescue StandardError => e
38
+ puts e.message
39
+ abort 'Unable to fetch remote data from: ' + endpoint
40
+ end
41
+ end
42
+ end
43
+
44
+ # Next try to grab any remote translations.
45
+ if site.config['remote_translations']
46
+ key = 'translations'
47
+ target = site.data[key]
48
+ site.config['remote_translations'].each do |endpoint|
49
+ begin
50
+ source = JSON.load(open(endpoint))
51
+ if target
52
+ target.deep_merge(source)
53
+ else
54
+ site.data[key] = source
55
+ end
56
+ rescue StandardError => e
57
+ puts e.message
58
+ abort 'Unable to fetch remote translation from: ' + endpoint
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -14,8 +14,10 @@ module JekyllOpenSdgPlugins
14
14
  site.data['meta'].each do |indicator_id, meta|
15
15
  if meta[language]
16
16
  meta.each do |meta_key, meta_value|
17
- if meta_key != language && !meta[language][meta_key]
18
- meta[language][meta_key] = meta_value
17
+ unless site.config['languages'].include? meta_key
18
+ if !meta[language][meta_key]
19
+ meta[language][meta_key] = meta_value
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllOpenSdgPlugins
2
- VERSION = "0.0.12".freeze
2
+ VERSION = "0.0.13".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: 0.0.12
4
+ version: 0.0.13
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-06-19 00:00:00.000000000 Z
11
+ date: 2019-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: deep_merge
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
27
41
  description: Jekyll plugins for use with the Open SDG platform
28
42
  email:
29
43
  - brockfanning@gmail.com
@@ -40,6 +54,7 @@ files:
40
54
  - lib/jekyll-open-sdg-plugins/create_goals.rb
41
55
  - lib/jekyll-open-sdg-plugins/create_indicators.rb
42
56
  - lib/jekyll-open-sdg-plugins/create_pages.rb
57
+ - lib/jekyll-open-sdg-plugins/fetch_remote_data.rb
43
58
  - lib/jekyll-open-sdg-plugins/get_indicator_name.rb
44
59
  - lib/jekyll-open-sdg-plugins/helpers.rb
45
60
  - lib/jekyll-open-sdg-plugins/multilingual_metadata.rb