jekyll-contentfyll 0.0.2 → 0.0.13
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/lib/jekyll/commands/fyll.rb +6 -6
- data/lib/jekyll-contentfyll/helpers.rb +7 -0
- data/lib/jekyll-contentfyll/importer.rb +101 -3
- data/lib/jekyll-contentfyll/version.rb +4 -4
- data/lib/jekyll-contentfyll.rb +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22b6a005f2ce306a378ca95fe6e553b72a3dae53978a45d68e2ecd2d4629ed86
|
4
|
+
data.tar.gz: 8ff78e5b386a7af784dfc333781fc8b245a74d3c42a061954a7a93f583436298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e22d3393c423b919da7a774d31aa7700adf904f6d11f409c0d34e322e3007b940f101800b457fbdfda97fa8936d755ba26ee964f0a3cafe0945c4cb63a1e39e9
|
7
|
+
data.tar.gz: 40f49202e98e07e927e84ac434176a9d41bb6de6f7da49c9ecba7c4c71590bf182d56dfec5c4c1715939ffb2802c7091853e13b727b9843a9b7e434be2cc797d
|
data/lib/jekyll/commands/fyll.rb
CHANGED
@@ -3,11 +3,11 @@ require 'jekyll-contentfyll/importer'
|
|
3
3
|
module Jekyll
|
4
4
|
# Module for Jekyll Commands
|
5
5
|
module Commands
|
6
|
-
# jekyll
|
6
|
+
# jekyll fyll Command
|
7
7
|
class Fyll < Command
|
8
8
|
def self.init_with_program(prog)
|
9
|
-
prog.command(:
|
10
|
-
c.syntax '
|
9
|
+
prog.command(:fyll) do |c|
|
10
|
+
c.syntax 'fyll [OPTIONS]'
|
11
11
|
c.description 'Imports data from Contentful'
|
12
12
|
|
13
13
|
options.each { |opt| c.option(*opt) }
|
@@ -35,11 +35,11 @@ module Jekyll
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.process(_args = [], options = {}, config = {})
|
38
|
-
Jekyll.logger.info '...Fylling...'
|
38
|
+
Jekyll.logger.info '... Fylling Content ...'
|
39
39
|
|
40
|
-
|
40
|
+
Jekyll::Contentfyll::Importer.new(config).run
|
41
41
|
|
42
|
-
|
42
|
+
Jekyll.logger.info '... Content Fylled ... '
|
43
43
|
|
44
44
|
# return unless options['rebuild']
|
45
45
|
|
@@ -1,5 +1,103 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'contentful'
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Contentfyll
|
5
|
+
# Importer class
|
6
|
+
#
|
7
|
+
# Entry fetching logic
|
8
|
+
class Importer
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
def initialize(jekyll_config)
|
12
|
+
@jekyll_config = jekyll_config
|
13
|
+
@config = jekyll_config.key?('contentful') ? jekyll_config['contentful'] : jekyll_config
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
spaces.each do |name, options|
|
19
|
+
space_client = client(
|
20
|
+
value_for(options, 'space'),
|
21
|
+
value_for(options, 'access_token'),
|
22
|
+
value_for(options, 'environment'),
|
23
|
+
client_options(options.fetch('client_options', {}))
|
24
|
+
)
|
25
|
+
|
26
|
+
export_data(name, space_client, options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def export_data(name, space_client, options)
|
31
|
+
Jekyll.logger.info space_client
|
32
|
+
entries = get_entries(space_client, options)
|
33
|
+
|
34
|
+
Jekyll.logger.info "Number of entries:"
|
35
|
+
Jekyll.logger.info entries.length
|
36
|
+
end
|
37
|
+
|
38
|
+
def value_for(options, key)
|
39
|
+
potential_value = options[key]
|
40
|
+
return ENV[potential_value.gsub('ENV_', '')] if !potential_value.nil? && potential_value.start_with?('ENV_')
|
41
|
+
potential_value
|
42
|
+
end
|
43
|
+
|
44
|
+
def spaces
|
45
|
+
config['spaces'].map(&:first)
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_entries(space_client, options)
|
49
|
+
cda_query = options.fetch('cda_query', {})
|
50
|
+
Jekyll.logger.info options
|
51
|
+
Jekyll.logger.info cda_query
|
52
|
+
return space_client.entries(cda_query) unless options.fetch('all_entries', false)
|
53
|
+
|
54
|
+
all = []
|
55
|
+
query = cda_query.clone
|
56
|
+
query[:order] = 'sys.createdAt' unless query.key?(:order)
|
57
|
+
num_entries = space_client.entries(limit: 1).total
|
58
|
+
|
59
|
+
page_size = options.fetch('all_entries_page_size', 1000)
|
60
|
+
|
61
|
+
Jekyll.logger.info num_entries
|
62
|
+
Jekyll.logger.info page_size
|
63
|
+
Jekyll.logger.info query
|
64
|
+
|
65
|
+
((num_entries / page_size) + 1).times do |i|
|
66
|
+
query[:limit] = page_size
|
67
|
+
query[:skip] = i * page_size
|
68
|
+
page = space_client.entries(query)
|
69
|
+
page.each { |entry| all << entry }
|
70
|
+
end
|
71
|
+
|
72
|
+
all
|
73
|
+
end
|
74
|
+
|
75
|
+
def client(space, access_token, environment = nil, options = {})
|
76
|
+
options = {
|
77
|
+
space: space,
|
78
|
+
access_token: access_token,
|
79
|
+
environment: environment || 'master',
|
80
|
+
dynamic_entries: :auto,
|
81
|
+
raise_errors: true,
|
82
|
+
integration_name: 'jekyll',
|
83
|
+
integration_version: Jekyll::Contentfyll::VERSION
|
84
|
+
}.merge(options)
|
85
|
+
|
86
|
+
::Contentful::Client.new(options)
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def client_options(options)
|
92
|
+
options = options.each_with_object({}) do |(k, v), memo|
|
93
|
+
memo[k.to_sym] = v
|
94
|
+
memo
|
95
|
+
end
|
96
|
+
|
97
|
+
options.delete(:dynamic_entries)
|
98
|
+
options.delete(:raise_errors)
|
99
|
+
options
|
100
|
+
end
|
101
|
+
end
|
4
102
|
end
|
5
103
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
|
4
|
-
|
1
|
+
module Jekyll
|
2
|
+
module Contentfyll
|
3
|
+
VERSION = '0.0.5'.freeze
|
4
|
+
end
|
5
5
|
end
|
data/lib/jekyll-contentfyll.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-contentfyll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chance Griffin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple hello world gem
|
14
14
|
email: cbg@hey.com
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- LICENSE.txt
|
21
21
|
- README.md
|
22
22
|
- lib/jekyll-contentfyll.rb
|
23
|
+
- lib/jekyll-contentfyll/helpers.rb
|
23
24
|
- lib/jekyll-contentfyll/importer.rb
|
24
25
|
- lib/jekyll-contentfyll/version.rb
|
25
26
|
- lib/jekyll/commands/fyll.rb
|