jekyll-strapi-4 1.0.2 → 1.0.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 +29 -0
- data/lib/jekyll/strapi/collection.rb +4 -0
- data/lib/jekyll/strapi/collection_permalink.rb +38 -0
- data/lib/jekyll/strapi/generator.rb +20 -4
- data/lib/jekyll/strapi/site.rb +11 -1
- data/lib/jekyll/strapi/version.rb +1 -1
- data/lib/jekyll-strapi.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4887f2576e671600cbba2f9d2243c5d5da9750233fc587b0fc925cd951188e2c
|
4
|
+
data.tar.gz: f4511e5d6e3d2965abb98abd9b22b1792298878c7f64f663d1e570cb3dd4a4db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4497758093430c168cc01674e7c9d3a270a82e29ef4dbb0162fb5f59d3e7004fccc193f0999bf7bc66767d506637c5d5f079f952815696d06ed8feebf2ec7462
|
7
|
+
data.tar.gz: ab120a2d4a43877a9c447e18296448e82cd60ec8f4daa3ba710cb32d8283a7bce56ad18e754d906a62a0f1cf5c01137b2637a10c10064ca362e8cee8f91c3a82
|
data/README.md
CHANGED
@@ -47,6 +47,9 @@ strapi:
|
|
47
47
|
# type: photos
|
48
48
|
# Permalink used to generate the output files (eg. /articles/:id).
|
49
49
|
permalink: /photos/:id/
|
50
|
+
# Permalinks defined for different locales
|
51
|
+
permalinks:
|
52
|
+
pl: "/zdjecia/:id"
|
50
53
|
# Parameters (optional)
|
51
54
|
parameters:
|
52
55
|
sort: title:asc
|
@@ -136,3 +139,29 @@ module Jekyll
|
|
136
139
|
end
|
137
140
|
end
|
138
141
|
```
|
142
|
+
|
143
|
+
### Permalinks
|
144
|
+
|
145
|
+
When you have a multi-language content, you might want generate a proper url based on different patterns, for example:
|
146
|
+
| Language | permalink pattern | example |
|
147
|
+
| ----------- | ----------- | - |
|
148
|
+
| en | /image/:slug |yourdomain.com/image/orange/ |
|
149
|
+
| es | /imagen/:slug | yourdomain.com/imagen/naranja/ |
|
150
|
+
| pl | /zdjecie/:slug | yourdomain.com/zdjecie/pomarancza/ |
|
151
|
+
|
152
|
+
In that case you have to
|
153
|
+
1. set locales [on request parameters](#request-parameters),
|
154
|
+
2. set permalinks patterns [on _config.yml](#configuration).
|
155
|
+
|
156
|
+
When you create permalinks, set default permalink and optionals permalinks.
|
157
|
+
|
158
|
+
```yaml
|
159
|
+
strapi:
|
160
|
+
collections:
|
161
|
+
photos:
|
162
|
+
permalink: /image/:slug/
|
163
|
+
permalinks:
|
164
|
+
es: /imagen/:slug
|
165
|
+
pl: /zdjecia/:slug
|
166
|
+
|
167
|
+
```
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Strapi
|
3
|
+
class StrapiCollectionPermalink
|
4
|
+
attr_reader :collection, :lang
|
5
|
+
|
6
|
+
def initialize(collection:, lang: nil)
|
7
|
+
@collection = collection
|
8
|
+
@lang = lang
|
9
|
+
end
|
10
|
+
|
11
|
+
def directory
|
12
|
+
use_different? ? permalinks[lang].split("/")[1] : collection.collection_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def exist?
|
16
|
+
config.key? 'permalink'
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
use_different? ? permalinks[lang] : config['permalink']
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def config
|
26
|
+
collection.config
|
27
|
+
end
|
28
|
+
|
29
|
+
def permalinks
|
30
|
+
config['permalinks']
|
31
|
+
end
|
32
|
+
|
33
|
+
def use_different?
|
34
|
+
permalinks && permalinks[lang]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -22,15 +22,31 @@ module Jekyll
|
|
22
22
|
@collection = collection
|
23
23
|
@document = document
|
24
24
|
|
25
|
-
@
|
25
|
+
@site.lang = @document.attributes.locale
|
26
|
+
|
27
|
+
@dir = @collection.config['output_dir'] || collection.permalink.directory
|
28
|
+
|
29
|
+
url = Jekyll::URL.new(
|
30
|
+
:placeholders => {
|
31
|
+
:id => document.id.to_s,
|
32
|
+
:uid => document.uid,
|
33
|
+
:slug => document.attributes.slug,
|
34
|
+
:type => document.attributes.type,
|
35
|
+
:date => document.attributes.date,
|
36
|
+
:title => document.title
|
37
|
+
},
|
38
|
+
permalink: collection.permalink.to_s
|
39
|
+
)
|
40
|
+
|
26
41
|
# Default file name, can be overwritten by permalink frontmatter setting
|
27
|
-
|
42
|
+
file_name = url.to_s.split("/").last
|
43
|
+
@name = "#{file_name}.html"
|
28
44
|
# filename_to_read = File.join(base, "_layouts"), @collection.config['layout']
|
29
45
|
|
30
46
|
self.process(@name)
|
31
47
|
self.read_yaml(File.join(base, "_layouts"), @collection.config['layout'])
|
32
|
-
if @collection.
|
33
|
-
self.data['permalink'] = @collection.
|
48
|
+
if @collection.permalink.exist?
|
49
|
+
self.data['permalink'] = @collection.permalink.to_s
|
34
50
|
end
|
35
51
|
|
36
52
|
self.data['document'] = StrapiDocumentDrop.new(@document)
|
data/lib/jekyll/strapi/site.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Jekyll
|
2
2
|
# Add helper methods for dealing with Strapi to the Site class
|
3
3
|
class Site
|
4
|
+
attr_accessor :lang
|
5
|
+
|
4
6
|
def strapi
|
5
7
|
return nil unless has_strapi?
|
6
8
|
end
|
@@ -25,7 +27,7 @@ module Jekyll
|
|
25
27
|
def strapi_link_resolver(collection = nil, document = nil)
|
26
28
|
return "/" unless collection != nil and @config['strapi']['collections'][collection]['permalink'] != nil
|
27
29
|
url = Jekyll::URL.new(
|
28
|
-
:template =>
|
30
|
+
:template => url_template(collection),
|
29
31
|
:placeholders => {
|
30
32
|
:id => document.id.to_s,
|
31
33
|
:uid => document.uid,
|
@@ -42,5 +44,13 @@ module Jekyll
|
|
42
44
|
def strapi_collection(collection_name)
|
43
45
|
strapi_collections[collection_name]
|
44
46
|
end
|
47
|
+
|
48
|
+
def url_template(collection)
|
49
|
+
permalink = @config['strapi']['collections'][collection]['permalink']
|
50
|
+
permalinks = @config['strapi']['collections'][collection]['permalinks']
|
51
|
+
|
52
|
+
return permalink unless permalinks && permalinks[lang]
|
53
|
+
"/#{lang}#{permalinks[lang]}"
|
54
|
+
end
|
45
55
|
end
|
46
56
|
end
|
data/lib/jekyll-strapi.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-strapi-4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Strapi Solutions
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- README.md
|
80
80
|
- lib/jekyll-strapi.rb
|
81
81
|
- lib/jekyll/strapi/collection.rb
|
82
|
+
- lib/jekyll/strapi/collection_permalink.rb
|
82
83
|
- lib/jekyll/strapi/drops.rb
|
83
84
|
- lib/jekyll/strapi/generator.rb
|
84
85
|
- lib/jekyll/strapi/hooks.rb
|