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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1da7a9d5781e7e2b4e4e3df79d1dc3cbd64c24aa
4
- data.tar.gz: 3481be3efe344fe79dcec661c54a551c7e6c5ff2
3
+ metadata.gz: df448bdd1c952a692f03ad79406f3058077f5c3c
4
+ data.tar.gz: abee56dbeebad848f3921559b505516aa6dabbfe
5
5
  SHA512:
6
- metadata.gz: 048abc0e3b9a9ef9a00bcf73104cae4cec0f555f826f47b640dcc17853824fada1d7f81f28793d01025cf8821f008e65cf2751fe243885ec9cd396d988ffd132
7
- data.tar.gz: fc35a1bf337cae4fcf13c8bf7bd40a56bf9a4ca0e821571b32ff37f091b8b829f929fec967f2090d4bee40eee09c492d85a7d7be4c1d61de95e0c22b744e5c2b
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
- All Entry fields can be used inside the layout templates as ``{{ page.fieldname }}``.
77
- The plugin adds two fields to pages generated from Contentful entries: ``{ page.contentful_id }}`` and ``{{ page.locale }}``.
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
 
@@ -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.inject({}){|x,(k,v)| x[k.to_s] = v; x}
21
+ fields = Jekyll::Utils.stringify_hash_keys(entry.fields)
22
+ self.data['contentful_fields'] = fields
21
23
 
22
- # merge data
23
- self.data.merge!(fields)
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["locale"] = entry.locale
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 |content_type_name|
57
- # Get ID for content type name
58
- content_type = client.content_types(name: content_type_name).first
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 \'#{content_type_name}\' does not exist." if content_type.nil?
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
- localization = site.config['contentful']['localization'] || [{locale: nil, url_prefix: ""}]
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
- entries = client.entries(content_type: content_type.id, locale: loc["locale"], limit: 1000)
72
+ next if entry.fields.nil?
67
73
 
68
- entries.each do |entry|
69
- next if entry.fields.nil?
70
-
71
- pub_langs = entry.fields[site.config['contentful']['published_locales_field'].to_sym]
72
-
73
- if pub_langs.nil? or pub_langs.map{|x| x.fields[:locale]}.include?(loc["locale"])
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.flatten.select do |that_page|
16
- that_page["contentful_id"] == this_page["contentful_id"] and that_page["locale"] != this_page["locale"]
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
- localization = @site.config['contentful']['localization'].detect{ |loc| loc["locale"] == page['locale']}
33
- "<a class='translation-link lang-#{page['locale']}' href='#{ page['url']}'>#{ localization["lang"] }</a>"
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
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Contentful
3
- VERSION = "0.1.5.pre2"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  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.pre2
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-08-21 00:00:00.000000000 Z
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: 1.3.1
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