jekyll-strapi-4 1.0.2 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6077c6d0a6e8d9dbe490114a666b001798510a2408d919965957721da1f83548
4
- data.tar.gz: 1604ceafb4e5caf8be5099b70a1370d93db7084fc949692f5b5e65c5b77d22ea
3
+ metadata.gz: 7289a0f9686e5f9289fe30b3580e2d7d005bd60e278558a31d273f5f1f97dcbd
4
+ data.tar.gz: 295affa7b21e10d7cc2a2fd6842c7dd480929666a24a1ab7d9cd78620773394f
5
5
  SHA512:
6
- metadata.gz: b441b56b74d1ad29990eeb3f377d5b022645da57784ab9fa6e2030a063db93f4ce2f7ce4c9aa0dfb0511c8cd1c8040d60e2e9401c6adf53b014f7052cb6befe8
7
- data.tar.gz: db8f35a82f8d64813bb54b6fdf25f1b28b1cf311e997794e78457cf4d7ecbd199056d0ebe9ccd13d0431684f6e0404527ee0a80150fa91d3dd4ff5553b65c614
6
+ metadata.gz: 77f96155a4de67a0b0dad619c1c3bd0c642ac5eeb3056105db22db2e9c3cac9fa6f06921f370b83bd2826a8ec90d8c10730f79fb5ca3e442e755b99eb70a5f18
7
+ data.tar.gz: 683951fef058e5d38d4a35d098cc175af841c5ed9cdc75099085520e7d1be45461f951103a2a54577edb8c3b8ccb02a6244646ce7a26bf6497d75b1417696762
data/README.md CHANGED
@@ -19,17 +19,17 @@ A: Every project deserves to have the cute deer as a logo.
19
19
 
20
20
  ## Install
21
21
 
22
- Add the "jekyll-strapi" gem to your Gemfile:
22
+ Add the "jekyll-strapi-4" gem to your Gemfile:
23
23
 
24
24
  ```
25
- gem "jekyll-strapi"
25
+ gem "jekyll-strapi-4"
26
26
  ```
27
27
 
28
- Then add "jekyll-strapi" to your plugins in `_config.yml`:
28
+ Then add "jekyll-strapi-4" to your plugins in `_config.yml`:
29
29
 
30
30
  ```
31
31
  plugins:
32
- - jekyll-strapi
32
+ - jekyll-strapi-4
33
33
  ```
34
34
 
35
35
  ## Configuration
@@ -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
+ ```
@@ -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
File without changes
@@ -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)
File without changes
@@ -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
File without changes
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Strapi
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.8"
4
4
  end
5
5
  end
@@ -0,0 +1,9 @@
1
+ require 'jekyll/strapi4/strapihttp'
2
+ require 'jekyll/strapi4/collection_permalink'
3
+ require 'jekyll/strapi4/collection'
4
+ require 'jekyll/strapi4/drops'
5
+ require 'jekyll/strapi4/generator'
6
+ require 'jekyll/strapi4/hooks'
7
+ require 'jekyll/strapi4/site'
8
+ require 'jekyll/strapi4/version'
9
+ require 'jekyll/tags/strapiimagefilter'
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.2
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Strapi Solutions
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-07-28 00:00:00.000000000 Z
13
+ date: 2022-07-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: down
@@ -77,14 +77,15 @@ extra_rdoc_files: []
77
77
  files:
78
78
  - LICENSE
79
79
  - README.md
80
- - lib/jekyll-strapi.rb
81
- - lib/jekyll/strapi/collection.rb
82
- - lib/jekyll/strapi/drops.rb
83
- - lib/jekyll/strapi/generator.rb
84
- - lib/jekyll/strapi/hooks.rb
85
- - lib/jekyll/strapi/site.rb
86
- - lib/jekyll/strapi/strapihttp.rb
87
- - lib/jekyll/strapi/version.rb
80
+ - lib/jekyll-strapi-4.rb
81
+ - lib/jekyll/strapi4/collection.rb
82
+ - lib/jekyll/strapi4/collection_permalink.rb
83
+ - lib/jekyll/strapi4/drops.rb
84
+ - lib/jekyll/strapi4/generator.rb
85
+ - lib/jekyll/strapi4/hooks.rb
86
+ - lib/jekyll/strapi4/site.rb
87
+ - lib/jekyll/strapi4/strapihttp.rb
88
+ - lib/jekyll/strapi4/version.rb
88
89
  - lib/jekyll/tags/strapiimagefilter.rb
89
90
  homepage: https://github.com/bluszcz/jekyll-strapi-4
90
91
  licenses:
data/lib/jekyll-strapi.rb DELETED
@@ -1,8 +0,0 @@
1
- require 'jekyll/strapi/strapihttp'
2
- require 'jekyll/strapi/collection'
3
- require 'jekyll/strapi/drops'
4
- require 'jekyll/strapi/generator'
5
- require 'jekyll/strapi/hooks'
6
- require 'jekyll/strapi/site'
7
- require 'jekyll/strapi/version'
8
- require 'jekyll/tags/strapiimagefilter'