jekyll-linked-posts 0.5.2 → 0.6.0

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: f33a1274ec184b4bc5cf5b9c7317303469d5d6ef479516d61e010763afd299b9
4
- data.tar.gz: 75ed922deb0dc1fc5e2fa85abc2e535c511e02fabda4598d70c70bd0cd4b3306
3
+ metadata.gz: 16d971d2aea65fdae7aa301bb61ed483c64c640e0606acfd7677d02f56de8147
4
+ data.tar.gz: 5ddf6ade823e07c478386c1c67f11dd9e3ef8bf9c9b5c0fc1972b8cb4291b8b5
5
5
  SHA512:
6
- metadata.gz: a151129dac5c6e6daa99386e6c97ab420cc2e5a6ed63d220f7628d058eed48c3702bb4597938e0601998cb116a9339b6d4404a67c3c28e37120df2a5c9328e35
7
- data.tar.gz: b26e964cda97e97c6a4ca571b4e59de63b4cf25021af5920420e8e1d87f8c48075fb78eab98a917319abb9256262eec3b06073dcd66913f5dc0f3ecb6e58e714
6
+ metadata.gz: 63fad8fd0d3aa089444acebd8280f5bc42c83ccf837e116215c096e56a9c3149b4f4cd09e8ded29131fd44d6cc5967f98be1128df9832a4ef17cb5bc2f8941a6
7
+ data.tar.gz: 447fbe203ca57f77e38207751ddfdc439549c512a77a67b7bc984efe6662b3b8c5382ca818d73b30fde57a6f1c4d161009f1e392d1df8ed21c099586de1fb716
checksums.yaml.gz.sig ADDED
Binary file
data/README.md CHANGED
@@ -91,6 +91,10 @@ linked_fields:
91
91
  These values are replaced by your configuration, so if you want to use
92
92
  them with other fields, re-add them to the configuration.
93
93
 
94
+ If you're using the [Sutty CMS](https://panel.sutty.nl), this plugin
95
+ supports Sutty's schemas, so it can link posts automatically. No need
96
+ for `linked_fields` in `_config.yml`.
97
+
94
98
  It also works between collections!
95
99
 
96
100
  ## Breadcrumbs
@@ -12,12 +12,10 @@ module Jekyll
12
12
  def breadcrumbs(input, field)
13
13
  return unless input.respond_to? :[]
14
14
 
15
- crumbs = [ input ]
16
- prev = input
15
+ crumbs = [input]
16
+ prev = input
17
17
 
18
- while prev&.public_send(:[], field)
19
- crumbs << (prev = prev[field])
20
- end
18
+ crumbs << (prev = prev[field]) while prev&.public_send(:[], field)
21
19
 
22
20
  crumbs.reverse
23
21
  end
@@ -8,6 +8,13 @@ module Jekyll
8
8
  # Value types allowed to index by
9
9
  INDEXABLE_TYPES = [String, Integer].freeze
10
10
 
11
+ # Field types that link to other documents on Sutty schemas.
12
+ SCHEMA_LINKED_FIELD_TYPES = %w[
13
+ locales related_posts
14
+ belongs_to has_many has_one has_and_belongs_to_many
15
+ new_belongs_to new_has_many new_has_one new_has_and_belongs_to_many
16
+ ].freeze
17
+
11
18
  attr_reader :site
12
19
 
13
20
  def initialize(site)
@@ -27,11 +34,34 @@ module Jekyll
27
34
 
28
35
  private
29
36
 
37
+ # @param message [String]
38
+ def warn(message)
39
+ Jekyll.logger.warn 'Linked:', message
40
+ end
41
+
42
+ # @param doc [Jekyll::Document,Jekyll::Page]
43
+ # @return [nil,Hash]
44
+ def schema_for(doc)
45
+ site.data.dig('schemas', doc['layout']) || site.data.dig('layouts', doc['layout'])
46
+ end
47
+
48
+ # @param schema [Hash]
49
+ # @return [Array<String>]
50
+ def linked_fields_for(schema)
51
+ schema.select do |_, value|
52
+ SCHEMA_LINKED_FIELD_TYPES.include? value['type']
53
+ end.keys
54
+ end
55
+
30
56
  # Processes fields from a document-like object
31
57
  #
32
58
  # @param :doc [Jekyll::Document,Jekyll::Page]
33
59
  # @return [nil]
34
60
  def process(doc)
61
+ schema = schema_for(doc)
62
+
63
+ @fields = linked_fields_for(schema) if schema
64
+
35
65
  fields.each do |field|
36
66
  next if (values = doc.data[field]).nil?
37
67
 
@@ -44,11 +74,11 @@ module Jekyll
44
74
  find doc
45
75
  end.compact
46
76
  when Hash
47
- values.map do |f, value|
48
- [f, v] if (v = find value)
49
- end.compact.to_h
77
+ values.transform_values do |value|
78
+ find value
79
+ end.compact
50
80
  else
51
- Jekyll.logger.warn "Couldn't link posts on #{doc.relative_path}"
81
+ warn "Couldn't link posts on #{doc.relative_path}"
52
82
  nil
53
83
  end
54
84
  end
@@ -56,6 +86,9 @@ module Jekyll
56
86
  nil
57
87
  end
58
88
 
89
+ # All documents and pages
90
+ #
91
+ # @return [Array]
59
92
  def indexable_documents
60
93
  @indexable_documents ||= site.documents + site.pages
61
94
  end
@@ -77,17 +110,17 @@ module Jekyll
77
110
  index_value = doc.data[indexed_field]
78
111
 
79
112
  unless index_value
80
- Jekyll.logger.warn "#{doc.relative_path} is missing field #{indexed_field}"
113
+ warn "#{doc.relative_path} is missing field #{indexed_field}"
81
114
  next docs
82
115
  end
83
116
 
84
117
  unless INDEXABLE_TYPES.include? index_value.class
85
- Jekyll.logger.warn "#{doc.relative_path} value for #{indexed_field} is #{index_value.class.downcase} instead of string or integer"
118
+ warn "#{doc.relative_path} value for #{indexed_field} is #{index_value.class} instead of #{INDEXABLE_TYPES.map(&:to_s).join(', ')}"
86
119
  next docs
87
120
  end
88
121
 
89
122
  if (dup = docs[index_value]) && dup != doc
90
- Jekyll.logger.warn "#{doc.relative_path} shares the same indexing value as #{dup.relative_path}: #{index_value}"
123
+ warn "#{doc.relative_path} shares the same indexing value as #{dup.relative_path}: #{index_value}"
91
124
  next docs
92
125
  end
93
126
 
@@ -105,7 +138,7 @@ module Jekyll
105
138
  # - related
106
139
  # - lang
107
140
  #
108
- # @return [Array]
141
+ # @return [Array<String>]
109
142
  def fields
110
143
  @fields ||= site.config.fetch('linked_fields', FIELDS).compact.uniq
111
144
  end
@@ -118,7 +151,7 @@ module Jekyll
118
151
  return value if value.is_a? Jekyll::Page
119
152
 
120
153
  indexed_documents[value].tap do |i|
121
- Jekyll.logger.warn "#{value} couldn't be found" if i.nil?
154
+ warn "#{value} couldn't be found" if i.nil?
122
155
  end
123
156
  end
124
157
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'jekyll/linked_posts'
2
4
  require_relative 'jekyll/filters/breadcrumbs'
3
5
 
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-linked-posts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2023-05-03 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEYDCCAsigAwIBAgIBATANBgkqhkiG9w0BAQsFADA7MQ4wDAYDVQQDDAVmYXVu
14
+ bzEVMBMGCgmSJomT8ixkARkWBXN1dHR5MRIwEAYKCZImiZPyLGQBGRYCbmwwHhcN
15
+ MjUwMTA3MTczMTQ1WhcNMjYwMTA3MTczMTQ1WjA7MQ4wDAYDVQQDDAVmYXVubzEV
16
+ MBMGCgmSJomT8ixkARkWBXN1dHR5MRIwEAYKCZImiZPyLGQBGRYCbmwwggGiMA0G
17
+ CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDqrFZ8PCNQbaW1incHEZp/OZTIt7bZ
18
+ TMKmkVLeRDqsSBGWTGdZbzRS6idn0vUKlTTnclPPG7dXw1r+AiYVdwIdjx16SLV1
19
+ ipbT/ezdzchfBVQHqdvExszAlL689iUnM9r22KkAXSzidSWuySjA5BY+8p1S2QO5
20
+ NcuB/+R5JRybVn6g500EB60jAZNUMM+2OlDqzS7oVqObOZ8zl8/HJaJnBGNNYLbN
21
+ cUY6qV9/0HUD2fS/eidBUGhg4jPKWHLHOZuXHPmGyE8bqdKC9T+Jbk/8KFM+SW7B
22
+ i4nZK4afoA6IT3KfQr5xnuyH0sUQj9M9eevWcGeGMTUv+ZiWM9zdJdyOvKhqjenX
23
+ G32KTR1tPgV6TK5jWyi7AHGos+2huBlKCsIJzDuw4zxs5cT9cVbkJFYHRIFQIHKq
24
+ gKSsTSUFt1ehfGtF/rLpv+Cm75BfZPi7OMePVE2FBaXBOvSRi0cYJkmuap9BjOut
25
+ OfvhZ41piDp/Kh0Cjgl1+o/fWTCh27yxb50CAwEAAaNvMG0wCQYDVR0TBAIwADAL
26
+ BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFIH0kjcsF7inzAwy488EEY5thfpiMBkGA1Ud
27
+ EQQSMBCBDmZhdW5vQHN1dHR5Lm5sMBkGA1UdEgQSMBCBDmZhdW5vQHN1dHR5Lm5s
28
+ MA0GCSqGSIb3DQEBCwUAA4IBgQCEo4E1ZAjlzw7LeJlju4BWUvKLjrbGiDNBYQir
29
+ lmyHhYXWV3gnozs08sM3BNzwsPwDwIhYOu3Kc+36DtEpKToUxqEGbsxX8uGzyp88
30
+ HTlaNsaHCZBeB2wgUYcIeO2lKdNu+V9WxfTRhYu+02OfLRv65qSfm6uck1Ml1Cg/
31
+ tn1Y7mLHSdnWPZCQhQZA0wX/SFL64DeozAwJLhYtKneU/m5PEqv9nNnJVCLlbODB
32
+ zFTjbsKtpWxNN+xWsJbjukggS8uX1400WqyjUCitDxDJknP+xeAg8wt2wT+IC1X1
33
+ zMY8gjxoBfwPum74cBTaZzYMpeGaS1fJ3N4NBU+SHLRDiKaVZzEnoNyJDHnsXXrX
34
+ MvF98+bTUHC9xcklH7RCO5uqUOq7cxIcMjzx3cpR6+AW6zXYQBjWfNB9KfaAstZy
35
+ cpurTQHNJfL/ah+9dYbgDXdG5HAAjRMAsWSvERw95YdN9XzQZCdUk5wUs+A6cNtO
36
+ AZZUMTVYNx8JqUeemxlXBRjsD/s=
37
+ -----END CERTIFICATE-----
38
+ date: 2025-04-02 00:00:00.000000000 Z
12
39
  dependencies:
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: jekyll
@@ -24,6 +51,20 @@ dependencies:
24
51
  - - "~>"
25
52
  - !ruby/object:Gem::Version
26
53
  version: '4'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rubocop
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
27
68
  description: Finds linked posts using UUIDs to make them available to Liquid
28
69
  email:
29
70
  - f@sutty.nl
@@ -71,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
112
  - !ruby/object:Gem::Version
72
113
  version: '0'
73
114
  requirements: []
74
- rubygems_version: 3.3.26
115
+ rubygems_version: 3.3.27
75
116
  signing_key:
76
117
  specification_version: 4
77
118
  summary: Adds linked posts to Jekyll
metadata.gz.sig ADDED
Binary file