jekyll-contentful 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/jekyll-contentful.rb +18 -41
- data/lib/jekyll-contentful/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5743688a84602c14bad1cc37a06c589d4d664bf0
|
4
|
+
data.tar.gz: 6ecd3ce5bf9e010546917d8494ca9d41b13e2b6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fd2e6533e12fc42461177105eefe15858b0ffff461fcc8846037cdc63eb44c7b7ac7df14074baa825054b1bcc308eef401bb0623014ebe7a1a818790ac9d6d8
|
7
|
+
data.tar.gz: 2bc8f11dcd8d2b3a2c921edabc1301b3ca8b3a0c979f6b0b30712eefb807cef5fc31b567874dc8e25cdae011d0823189d126cc74e3112a08d2f55603b573626d
|
data/README.md
CHANGED
@@ -33,16 +33,18 @@ Configure in your _config.yml file
|
|
33
33
|
|
34
34
|
```yaml
|
35
35
|
contentful:
|
36
|
-
|
37
|
-
|
36
|
+
preview: No
|
37
|
+
production_access_token: 'YOUR_PRODUCTION_TOKEN'
|
38
|
+
preview_access_token: 'YOUR_PREVIEW_TOKEN'
|
39
|
+
space: 'YOUR_SPACE'
|
38
40
|
content_types:
|
39
41
|
- "First Content Type"
|
40
42
|
- "Second Content Type"
|
41
43
|
localization:
|
42
44
|
- locale: en-US
|
43
|
-
url_prefix: "
|
45
|
+
url_prefix: ""
|
44
46
|
- locale: de-DE
|
45
|
-
url_prefix: "de"
|
47
|
+
url_prefix: "de/"
|
46
48
|
```
|
47
49
|
|
48
50
|
#### Content Fields:
|
data/lib/jekyll-contentful.rb
CHANGED
@@ -2,34 +2,6 @@ require "jekyll-contentful/version"
|
|
2
2
|
require "jekyll"
|
3
3
|
require "contentful"
|
4
4
|
|
5
|
-
#
|
6
|
-
# Configure in your _config.yml file
|
7
|
-
#
|
8
|
-
# contentful:
|
9
|
-
# access_token: 'YOUR_TOKEN'
|
10
|
-
# space: 'SPACE'
|
11
|
-
# content_types:
|
12
|
-
# - "First Content Type"
|
13
|
-
# - "Second Content Type"
|
14
|
-
# localization:
|
15
|
-
# - locale: en-US
|
16
|
-
# url_prefix: "en"
|
17
|
-
# - locale: de-DE
|
18
|
-
# url_prefix: "de"
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# Content Fields:
|
22
|
-
#
|
23
|
-
# All Entry fields can be used inside the layout templates as {{ page.fieldname }}
|
24
|
-
#
|
25
|
-
# ULRs and Layouts:
|
26
|
-
#
|
27
|
-
# Let's say you have a content type named "Blog Post" with an entry that has its title field set to "Awesome Title".
|
28
|
-
# The plugin will generate a page using the "blog-post.html" layout at the url: /en/blog-post/awesome-title/index.html
|
29
|
-
#
|
30
|
-
# If no layout named "blog-post.html" can be found the plugin will fallback to use the "default.html" layout.
|
31
|
-
#
|
32
|
-
|
33
5
|
module Jekyll
|
34
6
|
class ContentfulEntryPage < Page
|
35
7
|
def initialize(site, fields, content_type_name, prefix)
|
@@ -51,7 +23,7 @@ module Jekyll
|
|
51
23
|
|
52
24
|
# If there is a title fields make it the url
|
53
25
|
page_title_slug = Utils.slugify(self.data["title"] || "")
|
54
|
-
@dir = "
|
26
|
+
@dir = "/#{prefix}#{content_type_slug}/#{page_title_slug}"
|
55
27
|
|
56
28
|
self.process(@name)
|
57
29
|
end
|
@@ -62,9 +34,18 @@ module Jekyll
|
|
62
34
|
|
63
35
|
def generate(site)
|
64
36
|
|
37
|
+
if site.config['contentful']['preview']
|
38
|
+
api_url = 'preview.contentful.com'
|
39
|
+
access_token = site.config['contentful']['preview_access_token']
|
40
|
+
else
|
41
|
+
api_url = 'cdn.contentful.com'
|
42
|
+
access_token = site.config['contentful']['production_access_token']
|
43
|
+
end
|
44
|
+
|
65
45
|
client = ::Contentful::Client.new(
|
66
|
-
access_token:
|
67
|
-
space: site.config['contentful']['space']
|
46
|
+
access_token: access_token,
|
47
|
+
space: site.config['contentful']['space'],
|
48
|
+
api_url: api_url
|
68
49
|
)
|
69
50
|
|
70
51
|
# Loop over all content types
|
@@ -75,23 +56,19 @@ module Jekyll
|
|
75
56
|
throw "Content_type \'#{content_type_name}\' does not exist." if content_type.nil?
|
76
57
|
|
77
58
|
|
78
|
-
localization = site.config['contentful']['localization'] || [{locale: nil, url_prefix: ""}]
|
59
|
+
localization = site.config['contentful']['localization'] || [{locale: nil, url_prefix: ""}]
|
79
60
|
|
80
61
|
# Get all entries of content type
|
81
|
-
sync = client.sync(initial: true, type: 'Entry', content_type: content_type.id)
|
82
62
|
|
83
|
-
sync.each_page do |page|
|
84
|
-
puts "Generating #{page.items.count} entries of type \'#{content_type_name}\' (#{content_type.id})"
|
85
|
-
|
86
|
-
page.items.each do |item|
|
87
|
-
localization.each do |loc|
|
88
|
-
fields = loc["locale"].nil? ? item.fields : item.fields(loc["locale"])
|
89
|
-
site.pages << ContentfulEntryPage.new(site, fields, content_type_name, "/#{loc['url_prefix']}") unless fields.nil?
|
90
|
-
end
|
91
63
|
|
64
|
+
localization.each do |loc|
|
65
|
+
entries = client.entries(content_type: content_type.id, locale: loc["locale"], limit: 1000)
|
66
|
+
entries.each do |entry|
|
67
|
+
site.pages << ContentfulEntryPage.new(site, entry.fields, content_type_name, "#{loc['url_prefix']}") unless entry.fields.nil?
|
92
68
|
end
|
93
69
|
end
|
94
70
|
|
71
|
+
|
95
72
|
end
|
96
73
|
end
|
97
74
|
end
|