jekyll-strapi-4 1.0.0 → 1.0.4

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
  SHA256:
3
- metadata.gz: b60b83febefc6dfb99cc3f9d41cc0e4e2f82bce56e1e166ca6a04045357794f9
4
- data.tar.gz: a7a6f9c335cb714d7c52dc06ffd240eb70e18d3918c2b3eef0f9f8ab24dfb055
3
+ metadata.gz: 4887f2576e671600cbba2f9d2243c5d5da9750233fc587b0fc925cd951188e2c
4
+ data.tar.gz: f4511e5d6e3d2965abb98abd9b22b1792298878c7f64f663d1e570cb3dd4a4db
5
5
  SHA512:
6
- metadata.gz: 47db6f927bd95d671ca094db0dd4d0ca591401b2b3a1b3ae141097ae43fa7bef1530355cc8192f6d63803b58f8f53c97a584b045fb9fac90b57e1bc16382d66d
7
- data.tar.gz: 59e61272e81d10fff14524436f6a57cdee50518d3e9f699bdafdc486f001c62495c2c611c25d59fa7375edaf33651571978c019f13ae427b519b3c3079ff5523
6
+ metadata.gz: 4497758093430c168cc01674e7c9d3a270a82e29ef4dbb0162fb5f59d3e7004fccc193f0999bf7bc66767d506637c5d5f079f952815696d06ed8feebf2ec7462
7
+ data.tar.gz: ab120a2d4a43877a9c447e18296448e82cd60ec8f4daa3ba710cb32d8283a7bce56ad18e754d906a62a0f1cf5c01137b2637a10c10064ca362e8cee8f91c3a82
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  This plugin is based on the [jekyll-strapi](https://github.com/strapi-community/jekyll-strapi/) plugin.
4
4
 
5
+ ![](deer-jekyll-strapi-4.png?raw=true)
6
+
7
+ Q: Why the Deer for logo?
8
+
9
+ A: Every project deserves to have the cute deer as a logo.
10
+
5
11
  ## Features
6
12
 
7
13
  * Support for Strapi 4
@@ -41,6 +47,9 @@ strapi:
41
47
  # type: photos
42
48
  # Permalink used to generate the output files (eg. /articles/:id).
43
49
  permalink: /photos/:id/
50
+ # Permalinks defined for different locales
51
+ permalinks:
52
+ pl: "/zdjecia/:id"
44
53
  # Parameters (optional)
45
54
  parameters:
46
55
  sort: title:asc
@@ -130,3 +139,29 @@ module Jekyll
130
139
  end
131
140
  end
132
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
+ ```
@@ -60,6 +60,10 @@ module Jekyll
60
60
  @config['type'] || @collection_name
61
61
  end
62
62
 
63
+ def permalink
64
+ @permalink ||= StrapiCollectionPermalink.new(collection: self, lang: @site.lang)
65
+ end
66
+
63
67
  def populate
64
68
  @config["populate"] || "*"
65
69
  end
@@ -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
- @dir = @collection.config['output_dir'] || collection.collection_name
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
- @name = "#{document.id}.html"
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.config.key? 'permalink'
33
- self.data['permalink'] = @collection.config['permalink']
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)
@@ -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 => @config['strapi']['collections'][collection]['permalink'],
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
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Strapi
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
data/lib/jekyll-strapi.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'jekyll/strapi/strapihttp'
2
+ require 'jekyll/strapi/collection_permalink'
2
3
  require 'jekyll/strapi/collection'
3
4
  require 'jekyll/strapi/drops'
4
5
  require 'jekyll/strapi/generator'
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.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
@@ -86,7 +87,7 @@ files:
86
87
  - lib/jekyll/strapi/strapihttp.rb
87
88
  - lib/jekyll/strapi/version.rb
88
89
  - lib/jekyll/tags/strapiimagefilter.rb
89
- homepage: https://github.com/strapi/jekyll-strapi
90
+ homepage: https://github.com/bluszcz/jekyll-strapi-4
90
91
  licenses:
91
92
  - MIT
92
93
  metadata: {}