jekyll-contentful-data-import 1.3.0 → 1.4.0
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/CHANGELOG.md +7 -0
- data/README.md +39 -22
- data/lib/jekyll-contentful-data-import/data_exporter.rb +4 -1
- data/lib/jekyll-contentful-data-import/mappers/base.rb +9 -1
- data/lib/jekyll-contentful-data-import/version.rb +1 -1
- data/spec/jekyll-contentful/data_exporter_spec.rb +7 -0
- data/spec/jekyll-contentful/mappers/base_spec.rb +24 -0
- data/spec/spec_helper.rb +17 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07ed83d764273aa31d35ff66ccf3b1bdfb4f8d63
|
4
|
+
data.tar.gz: 9a354c8e5337733a735d375129b0e7f0ed878677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 785ea7b18d834a822eec3a6f884d422af77ad477b85a49e7deb0666857904b8a9ac7ac9b5c77d3d5dd780a7ebe533ce50b1f1139e28b99bc61ce5a143d5e3387
|
7
|
+
data.tar.gz: 5e5e68fb849d44072850b7ed712543f87acc8b142fa716204d2ff347d99231c535805abb93172a682d6122080c879d37c18a20fefadc3003030470c2b930b606
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## v1.4.0
|
6
|
+
### Fixed
|
7
|
+
* Fix Locale support [#29](https://github.com/contentful/jekyll-contentful-data-import/issues/29)
|
8
|
+
|
9
|
+
### Added
|
10
|
+
* Allow override destination directory using the `destination` key in the configuration [#27](https://github.com/contentful/jekyll-contentful-data-import/pull/27)
|
11
|
+
|
5
12
|
## v1.3.0
|
6
13
|
### Added
|
7
14
|
* Added the possibility to use `space` and `access_token` from environment variables [#14](https://github.com/contentful/jekyll-contentful-data-import/issues/14)
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ contentful:
|
|
54
54
|
client_options: # Optional
|
55
55
|
api_url: 'preview.contentful.com' # Defaults to 'api.contentful.com' which is Production
|
56
56
|
base_path: app_path # Optional - Defaults to Current directory
|
57
|
-
|
57
|
+
destination: destination_in_data # Optional - Defaults to _data/contentful/spaces
|
58
58
|
```
|
59
59
|
|
60
60
|
Parameter | Description
|
@@ -67,6 +67,7 @@ all_entries_page_size | Integer, the amount of maximum entries per CDA Request w
|
|
67
67
|
content_types | Hash describing the mapping applied to entries of the imported content types
|
68
68
|
client_options | Hash describing Contentful::Client configuration. See [contentful.rb](https://github.com/contentful/contentful.rb) for more info.
|
69
69
|
base_path | String with path to your Jekyll Application, defaults to current directory. Path is relative to your current location.
|
70
|
+
destination | String with path within _data under which to store the output yaml file. Defaults to contentful/spaces
|
70
71
|
|
71
72
|
You can add multiple spaces to your configuration
|
72
73
|
|
@@ -99,27 +100,6 @@ class MySysMapper < ::Jekyll::Contentful::Mappers::Base
|
|
99
100
|
end
|
100
101
|
```
|
101
102
|
|
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
|
-
|
123
103
|
#### Caveats
|
124
104
|
|
125
105
|
Jekyll itself only allows you to import code as plugins only for its recognized plugin entry points.
|
@@ -138,6 +118,43 @@ end
|
|
138
118
|
|
139
119
|
Then proceed to run: `bundle exec rake contentful`
|
140
120
|
|
121
|
+
### Hiding Space and Access Token in Public Repositories
|
122
|
+
|
123
|
+
In most cases you may want to avoid including your credentials in publicly available sites,
|
124
|
+
therefore you can do the following:
|
125
|
+
|
126
|
+
1. `bundle update`—make sure your gem version supports ENV_ variables
|
127
|
+
|
128
|
+
2. Set up your _config like so:
|
129
|
+
|
130
|
+
```yaml
|
131
|
+
contentful:
|
132
|
+
spaces:
|
133
|
+
- example:
|
134
|
+
space: ENV_CONTENTFUL_SPACE_ID
|
135
|
+
access_token: ENV_CONTENTFUL_ACCESS_TOKEN
|
136
|
+
```
|
137
|
+
(Your Space ID will be looked upon on `ENV['CONTENTFUL_SPACE_ID']` and your Access Token
|
138
|
+
on `ENV['CONTENTFUL_ACCESS_TOKEN']`.)
|
139
|
+
|
140
|
+
3. Either add the following variables to your shell's configuration file (.bashrc or .bash_profile, for example):
|
141
|
+
|
142
|
+
```bash
|
143
|
+
export CONTENTFUL_ACCESS_TOKEN=abc123
|
144
|
+
export CONTENTFUL_SPACE_ID=abc123
|
145
|
+
```
|
146
|
+
(And run `source ~/.bashrc` or open new terminal to enable changes.)
|
147
|
+
|
148
|
+
Or specify them on the command line:
|
149
|
+
|
150
|
+
```bash
|
151
|
+
CONTENTFUL_ACCESS_TOKEN=abc123 CONTENTFUL_SPACE_ID=abc123 jekyll contentful
|
152
|
+
```
|
153
|
+
4. Party.
|
154
|
+
|
155
|
+
This way, it is safe to share your code without having to worry
|
156
|
+
about your credentials.
|
157
|
+
|
141
158
|
## Examples
|
142
159
|
|
143
160
|
You can find working examples of multiple uses [here](https://github.com/contentful/contentful_jekyll_examples).
|
@@ -31,7 +31,10 @@ module Jekyll
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def destination_directory
|
34
|
-
File.join(base_directory, DATA_FOLDER, CONTENTFUL_FOLDER, SPACES_FOLDER)
|
34
|
+
destination_dir = File.join(base_directory, DATA_FOLDER, CONTENTFUL_FOLDER, SPACES_FOLDER)
|
35
|
+
destination_dir = File.join(base_directory, DATA_FOLDER, config['destination']) if config.key?('destination')
|
36
|
+
|
37
|
+
destination_dir
|
35
38
|
end
|
36
39
|
|
37
40
|
def destination_file
|
@@ -37,7 +37,7 @@ module Jekyll
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def has_multiple_locales?
|
40
|
-
config.fetch('cda_query', {}).fetch(
|
40
|
+
config.fetch('cda_query', {}).fetch('locale', nil) == '*'
|
41
41
|
end
|
42
42
|
|
43
43
|
def map_field(field_name, field_value)
|
@@ -57,6 +57,14 @@ module Jekyll
|
|
57
57
|
map_entry(value)
|
58
58
|
when ::Array
|
59
59
|
map_array(value)
|
60
|
+
when ::Symbol
|
61
|
+
value.to_s
|
62
|
+
when ::Hash
|
63
|
+
result = {}
|
64
|
+
value.each do |k, v|
|
65
|
+
result[k.to_s] = map_value(v)
|
66
|
+
end
|
67
|
+
result
|
60
68
|
else
|
61
69
|
value
|
62
70
|
end
|
@@ -43,6 +43,13 @@ describe Jekyll::Contentful::DataExporter do
|
|
43
43
|
expected = File.join(Dir.pwd, 'foo_dir', '_data', 'contentful', 'spaces', 'foo.yaml')
|
44
44
|
expect(subject.destination_file).to eq(expected)
|
45
45
|
end
|
46
|
+
|
47
|
+
it 'overridden destination' do
|
48
|
+
subject = described_class.new('foo', [], {'base_path' => 'foo_dir', 'destination' => 'bar_path'})
|
49
|
+
|
50
|
+
expected = File.join(Dir.pwd, 'foo_dir', '_data', 'bar_path', 'foo.yaml')
|
51
|
+
expect(subject.destination_file).to eq(expected)
|
52
|
+
end
|
46
53
|
end
|
47
54
|
|
48
55
|
describe '#setup_directory' do
|
@@ -106,4 +106,28 @@ describe Jekyll::Contentful::Mappers::Base do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
|
+
|
110
|
+
describe 'issues' do
|
111
|
+
describe '#29 - Fix localized entries' do
|
112
|
+
it 'should properly serialize a localized entry' do
|
113
|
+
config = {'cda_query' => { 'locale' => '*' } }
|
114
|
+
fields = {
|
115
|
+
'en-US' => { 'foo' => 'bar' },
|
116
|
+
'de-DE' => { 'foo' => 'baz' }
|
117
|
+
}
|
118
|
+
entry = EntryDouble.new('foo', ContentTypeDouble.new, fields, true)
|
119
|
+
mapper = described_class.new(entry, config)
|
120
|
+
|
121
|
+
expected = {
|
122
|
+
'sys' => { 'id' => 'foo' },
|
123
|
+
'foo' => {
|
124
|
+
'en-US' => 'bar',
|
125
|
+
'de-DE' => 'baz'
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
expect(mapper.map).to match expected
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
109
133
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,11 @@ require 'rspec'
|
|
7
7
|
require 'jekyll'
|
8
8
|
require File.expand_path('../../lib/jekyll-contentful-data-import.rb', __FILE__)
|
9
9
|
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.filter_run :focus => true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
end
|
14
|
+
|
10
15
|
VCR.configure do |config|
|
11
16
|
config.cassette_library_dir = "spec/fixtures/vcr_fixtures"
|
12
17
|
config.hook_into :webmock
|
@@ -33,12 +38,21 @@ class ContentTypeDouble
|
|
33
38
|
end
|
34
39
|
|
35
40
|
class EntryDouble < Contentful::DynamicEntry
|
36
|
-
attr_reader :id, :content_type
|
41
|
+
attr_reader :id, :content_type
|
37
42
|
|
38
|
-
def initialize(id = '', content_type = ContentTypeDouble.new, fields = {})
|
43
|
+
def initialize(id = '', content_type = ContentTypeDouble.new, fields = {}, locales = false)
|
39
44
|
@id = id
|
40
45
|
@content_type = content_type
|
41
|
-
|
46
|
+
|
47
|
+
if locales
|
48
|
+
@fields = fields
|
49
|
+
else
|
50
|
+
@fields = { 'en-US' => fields }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def locale
|
55
|
+
'en-US'
|
42
56
|
end
|
43
57
|
end
|
44
58
|
|
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.4.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-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|