gretel 4.1.0 → 4.2.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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +17 -0
- data/lib/gretel/renderer.rb +22 -1
- data/lib/gretel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b80e71f865388974401274f84159318e012a5e9e40800888549453e301881bec
|
4
|
+
data.tar.gz: 06d1a078802e9b8d175f17376c7534ba8004c15327e2fc75b0e01e9386653cb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b8c092e5e04c48099f0fcad18230b89a6f4c11e760d59f89f629792cb4225eb5db1cf4648c8a6145c6be99bcf104b0d08ee0b74b82d39d1e7b9e366fda6ea37
|
7
|
+
data.tar.gz: 582e6471d0fa5fb59d490bee9a41b1cdd7b0f419b107c9acb56914832ad5b3a5dfc5c4590918dcb38ea46495a0df2578ceeb5e6384e57c0ed7e37ab8e39ea3e7
|
data/CHANGELOG.md
CHANGED
@@ -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.
|
data/lib/gretel/renderer.rb
CHANGED
@@ -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
|
data/lib/gretel/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|