jekyll-contentful 0.1.5.pre2 → 0.1.5
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/README.md +34 -3
- data/lib/jekyll-contentful.rb +22 -19
- data/lib/jekyll-contentful/contentful-monkeypatch.rb +21 -0
- data/lib/jekyll-contentful/language_switcher_tag.rb +6 -9
- data/lib/jekyll-contentful/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df448bdd1c952a692f03ad79406f3058077f5c3c
|
4
|
+
data.tar.gz: abee56dbeebad848f3921559b505516aa6dabbfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75ade94f06fd6b481b04789b97ce18934723318dd4fbb4269f064007617190bee1968f4cdb9aa9e053dfe0db10d4c34721a62512d58d66d0c4455e49732d8668
|
7
|
+
data.tar.gz: 83dd0c47c5f274fe492c68f546c5a4a742ded186e288cc1d1b36a3ea5cb47286e2bc43959b6a7e4318de628e12a90b150a1ddb59c39debd750d9926074dc011a
|
data/README.md
CHANGED
@@ -73,9 +73,10 @@ You can also **specify** which **locales** should be published **on the entry le
|
|
73
73
|
Now for every entry you can specify the languages you want to generate pages for by adding them to your entries "published_languages" list.
|
74
74
|
|
75
75
|
#### Content Fields:
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
|
77
|
+
All Entry fields can be used inside the layout templates as {{ page.contentful_fields.fieldname }}.
|
78
|
+
The plugin adds two more fields to pages generated from Contentful entries: ``{ page.contentful_id }}`` and ``{{ page.contentful_locale }}``.
|
79
|
+
|
79
80
|
#### ULRs and Layouts:
|
80
81
|
|
81
82
|
Let's say you have a content type named "Blog Post" with an entry that has its title field set to "Awesome Title".
|
@@ -83,6 +84,36 @@ The plugin will generate a page using the "blog-post.html" layout at the url: /e
|
|
83
84
|
|
84
85
|
If no layout named "blog-post.html" can be found the plugin will fallback to use the "default.html" layout.
|
85
86
|
|
87
|
+
## Minimal Layout Example
|
88
|
+
|
89
|
+
the following example assumes a content type with two fields. A long text field named "body" and a short text field named "title".
|
90
|
+
|
91
|
+
```liquid
|
92
|
+
<!DOCTYPE html>
|
93
|
+
<html>
|
94
|
+
<body>
|
95
|
+
<header>
|
96
|
+
<div>
|
97
|
+
{% for p in site.pages %}
|
98
|
+
{% if p.title and page.contentful_locale == p.contentful_locale %}
|
99
|
+
{% if p.url == page.url %}
|
100
|
+
<span>{{ p.title }}</span>
|
101
|
+
{% else %}
|
102
|
+
<a href="{{ p.url | prepend: site.baseurl }}">{{ p.title }}</a>
|
103
|
+
{% endif %}
|
104
|
+
{% endif %}
|
105
|
+
{% endfor %}
|
106
|
+
</div>
|
107
|
+
</header>
|
108
|
+
<article>
|
109
|
+
<h1>{{ page.title }}</h1>
|
110
|
+
<p>{{ page.body | markdownify }}</p>
|
111
|
+
</article>
|
112
|
+
{% language_switcher %}
|
113
|
+
</body>
|
114
|
+
</html>
|
115
|
+
```
|
116
|
+
|
86
117
|
|
87
118
|
## License
|
88
119
|
|
data/lib/jekyll-contentful.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "jekyll"
|
2
2
|
require "contentful"
|
3
3
|
require "jekyll-contentful/version"
|
4
|
+
require "jekyll-contentful/contentful-monkeypatch"
|
4
5
|
require "jekyll-contentful/language_switcher_tag"
|
5
6
|
|
6
7
|
module Jekyll
|
@@ -17,13 +18,14 @@ module Jekyll
|
|
17
18
|
self.read_yaml(File.join(@base, '_layouts'), layout_filename)
|
18
19
|
|
19
20
|
# stringify hash keys
|
20
|
-
fields = entry.fields
|
21
|
+
fields = Jekyll::Utils.stringify_hash_keys(entry.fields)
|
22
|
+
self.data['contentful_fields'] = fields
|
21
23
|
|
22
|
-
|
23
|
-
self.data
|
24
|
+
display_field = entry.content_type.resolve.display_field
|
25
|
+
self.data['title'] = fields[display_field] if display_field
|
24
26
|
|
25
27
|
self.data["contentful_id"] = entry.id
|
26
|
-
self.data["
|
28
|
+
self.data["contentful_locale"] = entry.locale
|
27
29
|
|
28
30
|
# If there is a title fields make it the url
|
29
31
|
page_title_slug = Utils.slugify(self.data["title"] || "")
|
@@ -53,27 +55,28 @@ module Jekyll
|
|
53
55
|
)
|
54
56
|
|
55
57
|
# Loop over all content types
|
56
|
-
site.config['contentful']['content_types'].each do |
|
57
|
-
# Get
|
58
|
-
content_type = client.content_types(
|
58
|
+
site.config['contentful']['content_types'].each do |content_type_id|
|
59
|
+
# Get name for content type ID
|
60
|
+
content_type = client.content_types('sys.id' => content_type_id).first
|
59
61
|
|
60
|
-
throw "Content_type \'#{
|
62
|
+
throw "Content_type \'#{content_type_id}\' does not exist." if content_type.nil?
|
61
63
|
|
64
|
+
localization = site.config['contentful']['localization'] || [{locale: nil, url_prefix: ""}]
|
62
65
|
|
63
|
-
|
66
|
+
# Get all entries of content type
|
67
|
+
|
64
68
|
localization.each do |loc|
|
69
|
+
entries = client.entries(content_type: content_type_id, locale: loc["locale"], limit: 1000)
|
70
|
+
entries.each do |entry|
|
65
71
|
|
66
|
-
|
72
|
+
next if entry.fields.nil?
|
67
73
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
site.pages << ContentfulEntryPage.new(site, entry, content_type_name, "#{loc['url_prefix']}")
|
75
|
-
end
|
76
|
-
|
74
|
+
published_locales_field = site.config['contentful']['published_locales_field']
|
75
|
+
pub_langs = published_locales_field.nil? ? nil : entry.fields[published_locales_field.to_sym]
|
76
|
+
|
77
|
+
if pub_langs.nil? or pub_langs.map{|x| x.fields[:locale]}.include?(loc["locale"])
|
78
|
+
site.pages << ContentfulEntryPage.new(site, entry, content_type.name, "#{loc['url_prefix']}")
|
79
|
+
end
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Make asset arrays work in liquid templates
|
2
|
+
# e.g.
|
3
|
+
#
|
4
|
+
# {% for pic in page.gallery %}
|
5
|
+
# {{ pic.title }}
|
6
|
+
# <img src="{{ pic.file.url }}" />
|
7
|
+
# {% endfor %}
|
8
|
+
#
|
9
|
+
|
10
|
+
module Contentful
|
11
|
+
class Asset
|
12
|
+
def to_liquid
|
13
|
+
Jekyll::Utils.stringify_hash_keys(self.fields)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
class File
|
17
|
+
def to_liquid
|
18
|
+
Jekyll::Utils.stringify_hash_keys(self.properties)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -12,16 +12,13 @@ module Jekyll
|
|
12
12
|
|
13
13
|
return "" if @site.config['contentful']['localization'].nil? || this_page["contentful_id"].nil?
|
14
14
|
|
15
|
-
translated_pages = @site.pages.
|
16
|
-
that_page["contentful_id"] == this_page["contentful_id"] and that_page["
|
15
|
+
translated_pages = @site.pages.select do |that_page|
|
16
|
+
that_page["contentful_id"] == this_page["contentful_id"] and that_page["contentful_locale"] != this_page["contentful_locale"]
|
17
17
|
end
|
18
|
-
|
19
|
-
if translated_pages.length == 0
|
20
|
-
return
|
21
|
-
elsif translated_pages.length > 1
|
18
|
+
if translated_pages.length > 1
|
22
19
|
list = translated_pages.dup.map do |tp|
|
23
20
|
"<li translation-item>#{anchor(tp)}</li>"
|
24
|
-
end.join(
|
21
|
+
end.join()
|
25
22
|
return "<ul class='translation-list'>#{list}</uL>"
|
26
23
|
elsif translated_pages.length == 1
|
27
24
|
return anchor(translated_pages[0])
|
@@ -29,8 +26,8 @@ module Jekyll
|
|
29
26
|
end
|
30
27
|
|
31
28
|
def anchor(page)
|
32
|
-
|
33
|
-
"<a class='translation-link lang-#{page['
|
29
|
+
lang = @site.config['contentful']['localization'].detect{ |loc| loc["locale"] == page['contentful_locale']}["lang"]
|
30
|
+
"<a class='translation-link lang-#{page['contentful_locale']}' href='#{ page['url']}'>#{ lang }</a>"
|
34
31
|
end
|
35
32
|
end
|
36
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-contentful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.5
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dommmel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- jekyll-contentful.gemspec
|
82
82
|
- lib/jekyll-contentful.rb
|
83
|
+
- lib/jekyll-contentful/contentful-monkeypatch.rb
|
83
84
|
- lib/jekyll-contentful/language_switcher_tag.rb
|
84
85
|
- lib/jekyll-contentful/version.rb
|
85
86
|
homepage: https://github.com/dommmel/jekyll-contentful
|
@@ -97,12 +98,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
98
|
version: '0'
|
98
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
100
|
requirements:
|
100
|
-
- - "
|
101
|
+
- - ">="
|
101
102
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
103
|
+
version: '0'
|
103
104
|
requirements: []
|
104
105
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.4.5
|
106
|
+
rubygems_version: 2.4.5.1
|
106
107
|
signing_key:
|
107
108
|
specification_version: 4
|
108
109
|
summary: jekyll plugin that generates pages from contentful entries
|