gretel 4.1.0 → 4.2.0

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: d28cb34acf4eef47659c295f4dfd63b442fa7181552de3716015eb4f2d070c8f
4
- data.tar.gz: e8cb450b18ea1f00dffc6e580655931109ddd1389cafce109b1ab597e832761a
3
+ metadata.gz: b80e71f865388974401274f84159318e012a5e9e40800888549453e301881bec
4
+ data.tar.gz: 06d1a078802e9b8d175f17376c7534ba8004c15327e2fc75b0e01e9386653cb8
5
5
  SHA512:
6
- metadata.gz: a7b13ae376b35bfc5508472752bfac4cd98022a19d7e00e0c8535ba1aa7c44e07a5f5068d98c2ca364ad6d1f25adc8671090ef9ac7f2879328273c94a8ac4e1b
7
- data.tar.gz: 0e1451f51c1c2742c339a0b08489b2b503c3c751402eb432d0498b1b9ad2b44a1be2abf568c5f7387fed67aca07d959eb5bf9a41eb90d25f7b50beea3b6e09b4
6
+ metadata.gz: 3b8c092e5e04c48099f0fcad18230b89a6f4c11e760d59f89f629792cb4225eb5db1cf4648c8a6145c6be99bcf104b0d08ee0b74b82d39d1e7b9e366fda6ea37
7
+ data.tar.gz: 582e6471d0fa5fb59d490bee9a41b1cdd7b0f419b107c9acb56914832ad5b3a5dfc5c4590918dcb38ea46495a0df2578ceeb5e6384e57c0ed7e37ab8e39ea3e7
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 4.2.0
4
+ * Support generating JSON-LD structured data. See the readme for more info (via #26, thanks @dkniffin)
5
+
3
6
  ## Version 4.1.0
4
7
  * Depends only `railties` and `actionview`, not `rails` (via #7)
5
8
  * Include `Gretel::ViewHelpers` module in `ActiveSupport.on_load(:action_view)` block
data/README.md CHANGED
@@ -219,6 +219,23 @@ You can use the `breadcrumbs` method directly as an array. It will return an arr
219
219
  <% end %>
220
220
  ```
221
221
 
222
+ If you use this approach, you lose the built-in semantic breadcrumb functionality. One way to
223
+ add them back is to use JSON-LD structured data:
224
+
225
+ ```erb
226
+ <script type="application/ld+json">
227
+ <%= breadcrumbs.structured_data(url_base: "https://example.com")) %>
228
+ </script>
229
+ ```
230
+
231
+ Or, you can infer `url_base` from `request`:
232
+
233
+ ```erb
234
+ <script type="application/ld+json">
235
+ <%= breadcrumbs.structured_data(url_base: "#{request.protocol}#{request.host_with_port}")) %>
236
+ </script>
237
+ ```
238
+
222
239
  ## Getting the parent breadcrumb
223
240
 
224
241
  If you want to add a link to the parent breadcrumb, you can use the `parent_breadcrumb` view helper.
@@ -159,6 +159,27 @@ module Gretel
159
159
  concat links
160
160
  end
161
161
 
162
+ # Returns a hash matching the JSON-LD Structured Data schema
163
+ # https://developers.google.com/search/docs/data-types/breadcrumb#json-ld
164
+ def structured_data(url_base:)
165
+ url_base = url_base.chomp("/") # Remove trailing `/`, if present
166
+
167
+ items = @links.each_with_index.map do |link, i|
168
+ {
169
+ "@type": "ListItem",
170
+ "position": i + 1,
171
+ "name": link.text,
172
+ "item": "#{url_base}#{link.url}"
173
+ }
174
+ end
175
+
176
+ {
177
+ "@context": "https://schema.org",
178
+ "@type": "BreadcrumbList",
179
+ "itemListElement": items
180
+ }
181
+ end
182
+
162
183
  # Helper for returning all link keys to allow for simple testing.
163
184
  def keys
164
185
  map(&:key)
@@ -192,7 +213,7 @@ module Gretel
192
213
  end
193
214
 
194
215
  html = html_fragments.join(" ").html_safe
195
-
216
+
196
217
  if options[:semantic]
197
218
  content_tag(options[:container_tag], html, id: options[:id], class: options[:class], itemscope: "", itemtype: "https://schema.org/BreadcrumbList")
198
219
  else
@@ -1,3 +1,3 @@
1
1
  module Gretel
2
- VERSION = "4.1.0"
2
+ VERSION = "4.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gretel
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lasse Bunk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-09-20 00:00:00.000000000 Z
12
+ date: 2020-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties