jekyll-contentful 0.1.4 → 0.1.5.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -2
- data/lib/jekyll-contentful.rb +11 -7
- data/lib/jekyll-contentful/language_switcher_tag.rb +6 -4
- data/lib/jekyll-contentful/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1da7a9d5781e7e2b4e4e3df79d1dc3cbd64c24aa
|
4
|
+
data.tar.gz: 3481be3efe344fe79dcec661c54a551c7e6c5ff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 048abc0e3b9a9ef9a00bcf73104cae4cec0f555f826f47b640dcc17853824fada1d7f81f28793d01025cf8821f008e65cf2751fe243885ec9cd396d988ffd132
|
7
|
+
data.tar.gz: fc35a1bf337cae4fcf13c8bf7bd40a56bf9a4ca0e821571b32ff37f091b8b829f929fec967f2090d4bee40eee09c492d85a7d7be4c1d61de95e0c22b744e5c2b
|
data/README.md
CHANGED
@@ -31,6 +31,7 @@ gems: [jekyll-contentful]
|
|
31
31
|
|
32
32
|
Configure in your _config.yml file
|
33
33
|
|
34
|
+
|
34
35
|
```yaml
|
35
36
|
contentful:
|
36
37
|
preview: No
|
@@ -40,6 +41,7 @@ contentful:
|
|
40
41
|
content_types:
|
41
42
|
- "First Content Type"
|
42
43
|
- "Second Content Type"
|
44
|
+
published_locales_field: "published_languages"
|
43
45
|
localization:
|
44
46
|
- locale: en-US
|
45
47
|
url_prefix: ""
|
@@ -47,15 +49,32 @@ contentful:
|
|
47
49
|
- locale: de-DE
|
48
50
|
url_prefix: "de/"
|
49
51
|
lang: "Deutsch"
|
50
|
-
```
|
52
|
+
```
|
53
|
+
|
51
54
|
|
55
|
+
### Translations
|
56
|
+
You can globally specify the languages/locales that you want to generate pages for.
|
57
|
+
See the ``localization`` array in the ``_config.yml`` example above. You need to set the ``locale``, a string that this locale's urls will be prefixed with (``url_prefix``) and the language name (``lang``). The ``lang`` setting is used by the language switcher.
|
52
58
|
|
53
59
|
#### Language switcher
|
54
60
|
you can use the tag ``{% language_switcher %}`` in your templates to insert a link to the translations of the current page.
|
55
61
|
|
62
|
+
#### Selective Translations
|
63
|
+
By default the plugin will – for every entry – generate a page for every locale you specified in your ``_config.yml``.
|
64
|
+
|
65
|
+
You can also **specify** which **locales** should be published **on the entry level**:
|
66
|
+
|
67
|
+
1. Add a Content Type called "Languages" to your space (you can name it differently).
|
68
|
+
2. Add a field called "locale" to that content type (this field has to be called "locale" and nothing else).
|
69
|
+
3. Add an entry of that content type for every locale you have enabled in your space. Set those entries' "locale" field accordingly.
|
70
|
+
4. Add a reference field (many) to the content type you want to selectively translate. Call it "published_languages" (you can name it differently but it has to match the name in the next step). Set the validations to allow only the content type "Languages" to be referenced.
|
71
|
+
5. Add ``published_locales_field: "published_languages"`` in the ``contentful:``section of your ``_config.yml``
|
72
|
+
|
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.
|
56
74
|
|
57
75
|
#### Content Fields:
|
58
|
-
All Entry fields can be used inside the layout templates as {{ page.fieldname }}
|
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 }}``.
|
59
78
|
|
60
79
|
#### ULRs and Layouts:
|
61
80
|
|
data/lib/jekyll-contentful.rb
CHANGED
@@ -60,19 +60,23 @@ module Jekyll
|
|
60
60
|
throw "Content_type \'#{content_type_name}\' does not exist." if content_type.nil?
|
61
61
|
|
62
62
|
|
63
|
-
localization = site.config['contentful']['localization'] || [{locale: nil, url_prefix: ""}]
|
64
|
-
|
65
|
-
# Get all entries of content type
|
66
|
-
|
67
|
-
|
63
|
+
localization = site.config['contentful']['localization'] || [{locale: nil, url_prefix: ""}]
|
68
64
|
localization.each do |loc|
|
65
|
+
|
69
66
|
entries = client.entries(content_type: content_type.id, locale: loc["locale"], limit: 1000)
|
67
|
+
|
70
68
|
entries.each do |entry|
|
71
|
-
|
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
|
+
|
72
77
|
end
|
73
78
|
end
|
74
79
|
|
75
|
-
|
76
80
|
end
|
77
81
|
end
|
78
82
|
end
|
@@ -16,19 +16,21 @@ module Jekyll
|
|
16
16
|
that_page["contentful_id"] == this_page["contentful_id"] and that_page["locale"] != this_page["locale"]
|
17
17
|
end
|
18
18
|
|
19
|
-
if translated_pages.length
|
19
|
+
if translated_pages.length == 0
|
20
|
+
return
|
21
|
+
elsif translated_pages.length > 1
|
20
22
|
list = translated_pages.dup.map do |tp|
|
21
23
|
"<li translation-item>#{anchor(tp)}</li>"
|
22
24
|
end.join(' ,')
|
23
25
|
return "<ul class='translation-list'>#{list}</uL>"
|
24
|
-
|
26
|
+
elsif translated_pages.length == 1
|
25
27
|
return anchor(translated_pages[0])
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
31
|
def anchor(page)
|
30
|
-
|
31
|
-
"<a class='translation-link lang-#{page['locale']}' href='#{ page['url']}'>#{ lang }</a>"
|
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>"
|
32
34
|
end
|
33
35
|
end
|
34
36
|
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.
|
4
|
+
version: 0.1.5.pre2
|
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-
|
11
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -97,9 +97,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- - "
|
100
|
+
- - ">"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
102
|
+
version: 1.3.1
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
105
|
rubygems_version: 2.4.5
|