jekyll-contentful-data-import 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +39 -14
- data/lib/jekyll-contentful-data-import/importer.rb +29 -3
- data/lib/jekyll-contentful-data-import/version.rb +1 -1
- data/lib/jekyll/commands/contentful.rb +1 -1
- data/spec/jekyll-contentful/importer_spec.rb +46 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1babd5463d86525723186512d0a5ff1788b032c8
|
4
|
+
data.tar.gz: beedb4ade62bd19fa81a27afaf28070113018906
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5757f7558659b94941ac13d42750943c428b0827eac1eb0d5c7465447676d84a8a3bcca25e14ee699d66c2ee620edd31162aeff9ac89551ac2f7b32c5de1aed1
|
7
|
+
data.tar.gz: 391ff1027438166c09188e906e334cb04ef99acdd0987e4417a54c5cb1b41d01e8de6511e0a27b351fc7dba7728d9e9fcc8b851025dfb5553dd4411cd5001a9a
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Change Log
|
2
|
+
|
2
3
|
## Unreleased
|
3
4
|
|
5
|
+
## v1.3.0
|
6
|
+
### Added
|
7
|
+
* Added the possibility to use `space` and `access_token` from environment variables [#14](https://github.com/contentful/jekyll-contentful-data-import/issues/14)
|
8
|
+
* `all_entries` option to fetch entries over the 1000 limit of a single CDA request
|
9
|
+
* `all_entries_page_size` option to customize the size of the request for particularly heavy entries
|
10
|
+
|
4
11
|
## v1.2.1
|
5
12
|
### Fixed
|
6
13
|
* README showing incorrect configuration [#5](https://github.com/contentful/jekyll-contentful-data-import/issues/5)
|
data/README.md
CHANGED
@@ -42,27 +42,31 @@ To configure the extension, add the following configuration block to Jekyll's `_
|
|
42
42
|
contentful:
|
43
43
|
spaces:
|
44
44
|
- example: # Jekyll _data folder identifier - Required
|
45
|
-
space: cfexampleapi
|
46
|
-
access_token: b4c0n73n7fu1
|
47
|
-
cda_query:
|
45
|
+
space: cfexampleapi # Required
|
46
|
+
access_token: b4c0n73n7fu1 # Required
|
47
|
+
cda_query: # Optional
|
48
48
|
include: 2
|
49
49
|
limit: 100
|
50
|
-
|
50
|
+
all_entries: true # Optional - Defaults to false, only grabbing the amount set on CDA Query
|
51
|
+
all_entries_page_size: 1000 # Optional - Defaults to 1000, maximum amount of entries per CDA Request for all_entries
|
52
|
+
content_types: # Optional
|
51
53
|
cat: MyCoolMapper
|
52
|
-
client_options:
|
54
|
+
client_options: # Optional
|
53
55
|
api_url: 'preview.contentful.com' # Defaults to 'api.contentful.com' which is Production
|
54
|
-
base_path: app_path
|
56
|
+
base_path: app_path # Optional - Defaults to Current directory
|
55
57
|
|
56
58
|
```
|
57
59
|
|
58
|
-
Parameter
|
59
|
-
----------
|
60
|
-
space
|
61
|
-
access_token
|
62
|
-
cda_query
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
Parameter | Description
|
61
|
+
---------- | ------------
|
62
|
+
space | Contentful Space ID
|
63
|
+
access_token | Contentful Delivery API access token
|
64
|
+
cda_query | Hash describing query configuration. See [contentful.rb](https://github.com/contentful/contentful.rb) for more info (look for filter options there). Note that by default only 100 entries will be fetched, this can be configured to up to 1000 entries using the `limit` option.
|
65
|
+
all_entries | Boolean, if true will run multiple queries to the API until it fetches all entries for the space
|
66
|
+
all_entries_page_size | Integer, the amount of maximum entries per CDA Request when fetching :all_entries
|
67
|
+
content_types | Hash describing the mapping applied to entries of the imported content types
|
68
|
+
client_options | Hash describing Contentful::Client configuration. See [contentful.rb](https://github.com/contentful/contentful.rb) for more info.
|
69
|
+
base_path | String with path to your Jekyll Application, defaults to current directory. Path is relative to your current location.
|
66
70
|
|
67
71
|
You can add multiple spaces to your configuration
|
68
72
|
|
@@ -95,6 +99,27 @@ class MySysMapper < ::Jekyll::Contentful::Mappers::Base
|
|
95
99
|
end
|
96
100
|
```
|
97
101
|
|
102
|
+
### Hiding Space and Access Token in Public Repositories
|
103
|
+
|
104
|
+
In most cases you may want to avoid including your credentials in publicly available sites,
|
105
|
+
therefore you can hide your `space` and `access_token` by replacing them with `ENV_` prepended variables.
|
106
|
+
|
107
|
+
This will look for the values in your system.
|
108
|
+
|
109
|
+
For example:
|
110
|
+
|
111
|
+
```yaml
|
112
|
+
contentful:
|
113
|
+
spaces:
|
114
|
+
- example:
|
115
|
+
space: ENV_CONTENTFUL_SPACE_ID
|
116
|
+
access_token: ENV_CONTENTFUL_ACCESS_TOKEN
|
117
|
+
```
|
118
|
+
|
119
|
+
With this setup, your Space ID will be looked upon on `ENV['CONTENTFUL_SPACE_ID']` and your Access Token
|
120
|
+
on `ENV['CONTENTFUL_ACCESS_TOKEN']`. This way it is safe to share your code, without having to worry
|
121
|
+
about your credentials.
|
122
|
+
|
98
123
|
#### Caveats
|
99
124
|
|
100
125
|
Jekyll itself only allows you to import code as plugins only for its recognized plugin entry points.
|
@@ -13,23 +13,49 @@ module Jekyll
|
|
13
13
|
def run
|
14
14
|
spaces.each do |name, options|
|
15
15
|
space_client = client(
|
16
|
-
options
|
17
|
-
options
|
16
|
+
value_for(options, 'space'),
|
17
|
+
value_for(options, 'access_token'),
|
18
18
|
client_options(options.fetch('client_options', {}))
|
19
19
|
)
|
20
20
|
|
21
21
|
Jekyll::Contentful::DataExporter.new(
|
22
22
|
name,
|
23
|
-
space_client
|
23
|
+
get_entries(space_client, options),
|
24
24
|
options
|
25
25
|
).run
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def value_for(options, key)
|
30
|
+
potential_value = options[key]
|
31
|
+
return ENV[potential_value.gsub('ENV_', '')] if potential_value.start_with?('ENV_')
|
32
|
+
potential_value
|
33
|
+
end
|
34
|
+
|
29
35
|
def spaces
|
30
36
|
config['spaces'].map { |space_data| space_data.first }
|
31
37
|
end
|
32
38
|
|
39
|
+
def get_entries(space_client, options)
|
40
|
+
cda_query = options.fetch('cda_query', {})
|
41
|
+
return space_client.entries(cda_query) unless options.fetch('all_entries', false)
|
42
|
+
|
43
|
+
all = []
|
44
|
+
query = cda_query.clone
|
45
|
+
query[:order] = 'sys.createdAt' unless query.key?(:order)
|
46
|
+
num_entries = space_client.entries(limit: 1).total
|
47
|
+
|
48
|
+
page_size = options.fetch('all_entries_page_size', 1000)
|
49
|
+
((num_entries / page_size) + 1).times do |i|
|
50
|
+
query[:limit] = page_size
|
51
|
+
query[:skip] = i * page_size
|
52
|
+
page = space_client.entries(query)
|
53
|
+
page.each { |entry| all << entry }
|
54
|
+
end
|
55
|
+
|
56
|
+
all
|
57
|
+
end
|
58
|
+
|
33
59
|
def client(space, access_token, options = {})
|
34
60
|
options = {
|
35
61
|
space: space,
|
@@ -8,7 +8,7 @@ module Jekyll
|
|
8
8
|
c.syntax 'contentful [OPTIONS]'
|
9
9
|
c.description 'Imports data from Contentful'
|
10
10
|
|
11
|
-
options.each {|opt| c.option
|
11
|
+
options.each {|opt| c.option(*opt) }
|
12
12
|
|
13
13
|
c.action do |args, options|
|
14
14
|
contentful_config = Jekyll.configuration['contentful']
|
@@ -1,8 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class EntryArrayDouble < ::Array
|
4
|
+
def total
|
5
|
+
size
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
class ClientDouble
|
10
|
+
def initialize(response = EntryArrayDouble.new)
|
11
|
+
@response = response
|
12
|
+
end
|
13
|
+
|
4
14
|
def entries(options = {})
|
5
|
-
|
15
|
+
@response
|
6
16
|
end
|
7
17
|
end
|
8
18
|
|
@@ -44,9 +54,20 @@ describe Jekyll::Contentful::Importer do
|
|
44
54
|
end
|
45
55
|
end
|
46
56
|
|
57
|
+
describe '#value_for' do
|
58
|
+
it 'returns set value regularly' do
|
59
|
+
expect(subject.value_for({'foo' => 'bar'}, 'foo')).to eq 'bar'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns ENV value if prefixed with ENV_' do
|
63
|
+
ENV['bar'] = 'bar_from_env'
|
64
|
+
expect(subject.value_for({'foo' => 'ENV_bar'}, 'foo')).to eq 'bar_from_env'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
47
68
|
describe '#run' do
|
48
69
|
it 'runs exporter for each space' do
|
49
|
-
allow(subject).to receive(:spaces).and_return([['foo', {}], ['bar', {}]])
|
70
|
+
allow(subject).to receive(:spaces).and_return([['foo', {'space' => 'foo', 'access_token' => 'bar'}], ['bar', {'space' => 'bar', 'access_token' => 'foo'}]])
|
50
71
|
allow(subject).to receive(:client).and_return(ClientDouble.new)
|
51
72
|
|
52
73
|
expect(Jekyll::Contentful::DataExporter).to receive(:new).and_return(ExporterDouble.new).twice
|
@@ -62,5 +83,28 @@ describe Jekyll::Contentful::Importer do
|
|
62
83
|
subject.run
|
63
84
|
end
|
64
85
|
end
|
86
|
+
|
87
|
+
describe '#get_entries' do
|
88
|
+
it 'runs a single query by default' do
|
89
|
+
client = ClientDouble.new
|
90
|
+
expect(client).to receive(:entries).once
|
91
|
+
|
92
|
+
subject.get_entries(client, {})
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'fetches all entries when all_entries is set' do
|
96
|
+
client = ClientDouble.new(EntryArrayDouble.new([1, 2, 3]))
|
97
|
+
expect(client).to receive(:entries).and_call_original.twice
|
98
|
+
|
99
|
+
subject.get_entries(client, {'all_entries' => true})
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'can select page size when all_entries by using all_entries_page_size' do
|
103
|
+
client = ClientDouble.new(EntryArrayDouble.new([1, 2, 3]))
|
104
|
+
expect(client).to receive(:entries).and_call_original.exactly(3).times
|
105
|
+
|
106
|
+
subject.get_entries(client, {'all_entries' => true, 'all_entries_page_size' => 2})
|
107
|
+
end
|
108
|
+
end
|
65
109
|
end
|
66
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-contentful-data-import
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentful GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
223
223
|
version: '0'
|
224
224
|
requirements: []
|
225
225
|
rubyforge_project:
|
226
|
-
rubygems_version: 2.5.
|
226
|
+
rubygems_version: 2.5.1
|
227
227
|
signing_key:
|
228
228
|
specification_version: 4
|
229
229
|
summary: Include mangablable content from the Contentful CMS and API into your Jekyll
|