jekyll-contentful 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/lib/jekyll-contentful.rb +8 -4
- data/lib/jekyll-contentful/language_switcher_tag.rb +36 -0
- data/lib/jekyll-contentful/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 637ee259884f12976d992cafd510bc4f1afb0a86
|
4
|
+
data.tar.gz: a979832be89ce18ad4d143e838fb080d118b25ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a917a98be702cd8099132fba82fab900b2767c7e8fb9e57ec7d46f0eca6bc1aafa1d2459e6cb5578294b18c53970afb939ccede3262db57e15bc5aabd71fc0cb
|
7
|
+
data.tar.gz: f2aaa90fc7e0024c3c1082c0042ee60820bfda7fc02fa201580930ba6fb635b1bd07443d742ec24fdffbedeb938e46e2ab9d6a8e43de70811bebaae55f9f6de5
|
data/README.md
CHANGED
@@ -42,11 +42,18 @@ contentful:
|
|
42
42
|
- "Second Content Type"
|
43
43
|
localization:
|
44
44
|
- locale: en-US
|
45
|
-
|
45
|
+
url_prefix: ""
|
46
|
+
lang: "English"
|
46
47
|
- locale: de-DE
|
47
|
-
|
48
|
+
url_prefix: "de/"
|
49
|
+
lang: "Deutsch"
|
48
50
|
```
|
49
|
-
|
51
|
+
|
52
|
+
|
53
|
+
#### Language switcher
|
54
|
+
you can use the tag ``{% language_switcher %}`` in your templates to insert a link to the translations of the current page.
|
55
|
+
|
56
|
+
|
50
57
|
#### Content Fields:
|
51
58
|
All Entry fields can be used inside the layout templates as {{ page.fieldname }}
|
52
59
|
|
data/lib/jekyll-contentful.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require "jekyll-contentful/version"
|
2
1
|
require "jekyll"
|
3
2
|
require "contentful"
|
3
|
+
require "jekyll-contentful/version"
|
4
|
+
require "jekyll-contentful/language_switcher_tag"
|
4
5
|
|
5
6
|
module Jekyll
|
6
7
|
class ContentfulEntryPage < Page
|
7
|
-
def initialize(site,
|
8
|
+
def initialize(site, entry, content_type_name, prefix)
|
8
9
|
|
9
10
|
@site = site
|
10
11
|
@base = site.source
|
@@ -16,11 +17,14 @@ module Jekyll
|
|
16
17
|
self.read_yaml(File.join(@base, '_layouts'), layout_filename)
|
17
18
|
|
18
19
|
# stringify hash keys
|
19
|
-
fields = fields.inject({}){|x,(k,v)| x[k.to_s] = v; x}
|
20
|
+
fields = entry.fields.inject({}){|x,(k,v)| x[k.to_s] = v; x}
|
20
21
|
|
21
22
|
# merge data
|
22
23
|
self.data.merge!(fields)
|
23
24
|
|
25
|
+
self.data["contentful_id"] = entry.id
|
26
|
+
self.data["locale"] = entry.locale
|
27
|
+
|
24
28
|
# If there is a title fields make it the url
|
25
29
|
page_title_slug = Utils.slugify(self.data["title"] || "")
|
26
30
|
@dir = "/#{prefix}#{content_type_slug}/#{page_title_slug}"
|
@@ -64,7 +68,7 @@ module Jekyll
|
|
64
68
|
localization.each do |loc|
|
65
69
|
entries = client.entries(content_type: content_type.id, locale: loc["locale"], limit: 1000)
|
66
70
|
entries.each do |entry|
|
67
|
-
site.pages << ContentfulEntryPage.new(site, entry
|
71
|
+
site.pages << ContentfulEntryPage.new(site, entry, content_type_name, "#{loc['url_prefix']}") unless entry.fields.nil?
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Jekyll
|
2
|
+
class LanguageSwitcherTag < Liquid::Tag
|
3
|
+
|
4
|
+
def initialize(tag_name, text, tokens)
|
5
|
+
super
|
6
|
+
@text = text
|
7
|
+
end
|
8
|
+
|
9
|
+
def render(context)
|
10
|
+
@site = context.registers[:site]
|
11
|
+
this_page = context.registers[:page]
|
12
|
+
|
13
|
+
return "" if @site.config['contentful']['localization'].nil? || this_page["contentful_id"].nil?
|
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"]
|
17
|
+
end
|
18
|
+
|
19
|
+
if translated_pages.length > 1
|
20
|
+
list = translated_pages.dup.map do |tp|
|
21
|
+
"<li translation-item>#{anchor(tp)}</li>"
|
22
|
+
end.join(' ,')
|
23
|
+
return "<ul class='translation-list'>#{list}</uL>"
|
24
|
+
else
|
25
|
+
return anchor(translated_pages[0])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def anchor(page)
|
30
|
+
lang = @site.config['contentful']['localization'].detect{ |loc| loc["locale"] == page['locale']}["lang"]
|
31
|
+
"<a class='translation-link lang-#{page['locale']}' href='#{ page['url']}'>#{ lang }</a>"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Liquid::Template.register_tag('language_switcher', Jekyll::LanguageSwitcherTag)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dommmel
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- jekyll-contentful.gemspec
|
82
82
|
- lib/jekyll-contentful.rb
|
83
|
+
- lib/jekyll-contentful/language_switcher_tag.rb
|
83
84
|
- lib/jekyll-contentful/version.rb
|
84
85
|
homepage: https://github.com/dommmel/jekyll-contentful
|
85
86
|
licenses:
|