jekyll-contentful-data-import 1.1.0 → 1.2.0
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 507dfdec0af831cf69432858fa3bd9621c6467a7
|
4
|
+
data.tar.gz: 37ff563f3bcc5f664b968a2512b0e5444f953f41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1db27059f3fd320f1782ec9a70db90d03e40b799602c19d76d90fedc52980b7acfd7f9a26490e180d3697bebde0140d3d99e0e2a7d3c7c0d9fe1f493121f5fad
|
7
|
+
data.tar.gz: 7976a3fafc41fcda41b86bf4b22ff60696c8bc99c831283ff05e6aa905173c8fdce57964dac02af75a2ea4ee9a4ce7e4e931a9866f6123f9789f549a1c6a963d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Jekyll-Contentful-Data-Import
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.
|
3
|
+
[![Build Status](https://travis-ci.org/contentful/jekyll-contentful-data-import.svg?branch=master)](https://travis-ci.org/contentful/jekyll-contentful-data-import)
|
4
4
|
|
5
5
|
Jekyll-Contentful-Data-Import is a [Jekyll](http://jekyllrb.com/) extension to use the Jekyll static site generator together with the API-driven [Contentful CMS](https://www.contentful.com). It is powered by the [Contentful Ruby Gem](https://github.com/contentful/contentful.rb).
|
6
6
|
|
@@ -51,6 +51,8 @@ contentful:
|
|
51
51
|
:preview: false
|
52
52
|
:raise_errors: true
|
53
53
|
:dynamic_entries: :auto
|
54
|
+
base_path: app_path # Optional - Defaults to Current directory
|
55
|
+
|
54
56
|
```
|
55
57
|
|
56
58
|
Parameter | Description
|
@@ -60,6 +62,7 @@ access_token | Contentful Delivery API access token
|
|
60
62
|
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.
|
61
63
|
content_types | Hash describing the mapping applied to entries of the imported content types
|
62
64
|
client_options | Hash describing Contentful::Client configuration. See [contentful.rb](https://github.com/contentful/contentful.rb) for more info.
|
65
|
+
base_path | String with path to your Jekyll Application, defaults to current directory. Path is relative to your current location.
|
63
66
|
|
64
67
|
You can add multiple spaces to your configuration
|
65
68
|
|
@@ -70,7 +73,7 @@ data folder. If a custom mapper is not specified a default one will be used.
|
|
70
73
|
|
71
74
|
The default mapper will map fields, assets and linked entries.
|
72
75
|
|
73
|
-
### Custom
|
76
|
+
### Custom Mappers
|
74
77
|
|
75
78
|
You can create your own mappers if you need so. The only requirement for a class to behave as a
|
76
79
|
mapper is to have a `map` instance method.
|
@@ -92,3 +95,29 @@ class MySysMapper < ::Jekyll::Contentful::Mappers::Base
|
|
92
95
|
end
|
93
96
|
```
|
94
97
|
|
98
|
+
#### Caveats
|
99
|
+
|
100
|
+
Jekyll itself only allows to import code as plugins only for it's recognized plugin entry points.
|
101
|
+
Therefore we need to use a custom [Rakefile](https://github.com/contentful/contentful_jekyll_examples/blob/master/examples/custom_mapper/example/Rakefile) to import the mapper and required files:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
require 'jekyll'
|
105
|
+
require 'jekyll-contentful-data-import'
|
106
|
+
require './_plugins/mappers'
|
107
|
+
|
108
|
+
desc "Import Contentful Data with Custom Mappers"
|
109
|
+
task :contentful do
|
110
|
+
Jekyll::Commands::Contentful.process([], {}, Jekyll.configuration['contentful'])
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
Then proceed to run: `bundle exec rake contentful`
|
115
|
+
|
116
|
+
## Examples
|
117
|
+
|
118
|
+
You can find working examples of multiple uses [here](https://github.com/contentful/contentful_jekyll_examples).
|
119
|
+
|
120
|
+
## Contributing
|
121
|
+
|
122
|
+
Feel free to add your own examples by submitting a Pull Request. For more information,
|
123
|
+
please check [CONTRIBUTING.md](./CONTRIBUTING.md)
|
@@ -23,8 +23,14 @@ module Jekyll
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
def base_directory
|
27
|
+
directory = File.expand_path(Dir.pwd)
|
28
|
+
directory = File.join(directory, config['base_path']) if config.key?('base_path')
|
29
|
+
|
30
|
+
directory
|
31
|
+
end
|
32
|
+
|
26
33
|
def destination_directory
|
27
|
-
base_directory = File.expand_path(Dir.pwd)
|
28
34
|
File.join(base_directory, DATA_FOLDER, CONTENTFUL_FOLDER, SPACES_FOLDER)
|
29
35
|
end
|
30
36
|
|
@@ -33,14 +39,7 @@ module Jekyll
|
|
33
39
|
end
|
34
40
|
|
35
41
|
def setup_directory
|
36
|
-
|
37
|
-
Dir.mkdir(data_folder) unless Dir.exist?(data_folder)
|
38
|
-
|
39
|
-
contentful_folder = File.join(data_folder, CONTENTFUL_FOLDER)
|
40
|
-
Dir.mkdir(contentful_folder) unless Dir.exist?(contentful_folder)
|
41
|
-
|
42
|
-
spaces_folder = File.join(contentful_folder, SPACES_FOLDER)
|
43
|
-
Dir.mkdir(spaces_folder) unless Dir.exist?(spaces_folder)
|
42
|
+
FileUtils.mkdir_p destination_directory
|
44
43
|
end
|
45
44
|
end
|
46
45
|
end
|
@@ -5,22 +5,62 @@ describe Jekyll::Contentful::DataExporter do
|
|
5
5
|
subject { described_class.new('foo', []) }
|
6
6
|
|
7
7
|
describe 'instance methods' do
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
describe '#base_directory' do
|
9
|
+
it 'default directory' do
|
10
|
+
expect(subject.base_directory).to eq(Dir.pwd)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'overriden directory' do
|
14
|
+
subject = described_class.new('foo', [], {'base_path' => 'foo_dir'})
|
15
|
+
|
16
|
+
expect(subject.base_directory).to eq(File.join(Dir.pwd, 'foo_dir'))
|
17
|
+
end
|
11
18
|
end
|
12
19
|
|
13
|
-
|
14
|
-
|
15
|
-
|
20
|
+
describe '#destination_directory' do
|
21
|
+
it 'default directory' do
|
22
|
+
expected = File.join(Dir.pwd, '_data', 'contentful', 'spaces')
|
23
|
+
expect(subject.destination_directory).to eq(expected)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'overriden directory' do
|
27
|
+
subject = described_class.new('foo', [], {'base_path' => 'foo_dir'})
|
28
|
+
|
29
|
+
expected = File.join(Dir.pwd, 'foo_dir', '_data', 'contentful', 'spaces')
|
30
|
+
expect(subject.destination_directory).to eq(expected)
|
31
|
+
end
|
16
32
|
end
|
17
33
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
34
|
+
describe '#destination_file' do
|
35
|
+
it 'default directory' do
|
36
|
+
expected = File.join(Dir.pwd, '_data', 'contentful', 'spaces', 'foo.yaml')
|
37
|
+
expect(subject.destination_file).to eq(expected)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'overridden directory' do
|
41
|
+
subject = described_class.new('foo', [], {'base_path' => 'foo_dir'})
|
22
42
|
|
23
|
-
|
43
|
+
expected = File.join(Dir.pwd, 'foo_dir', '_data', 'contentful', 'spaces', 'foo.yaml')
|
44
|
+
expect(subject.destination_file).to eq(expected)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#setup_directory' do
|
49
|
+
it 'default directory' do
|
50
|
+
expected = File.join(Dir.pwd, '_data', 'contentful', 'spaces')
|
51
|
+
expect(FileUtils).to receive(:mkdir_p).with(expected)
|
52
|
+
|
53
|
+
subject.setup_directory
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'overridden directory' do
|
57
|
+
subject = described_class.new('foo', [], {'base_path' => 'foo_dir'})
|
58
|
+
|
59
|
+
expected = File.join(Dir.pwd, 'foo_dir', '_data', 'contentful', 'spaces')
|
60
|
+
expect(FileUtils).to receive(:mkdir_p).with(expected)
|
61
|
+
|
62
|
+
subject.setup_directory
|
63
|
+
end
|
24
64
|
end
|
25
65
|
|
26
66
|
describe '#run' do
|
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.2.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:
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|