page_structured_data 1.0.1 → 1.0.2
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/README.md +203 -55
- data/lib/page_structured_data/engine.rb +3 -0
- data/lib/page_structured_data/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: 8e6e417c38d0a25d8e3270315eb9d98434eb9dbc93e7860667a96e457b94bfa9
|
|
4
|
+
data.tar.gz: e3f2b717b5b01cd49c90675fb1a74199b89492c298fa93474ad75772530edf32
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 80bc6fed7640148b6f7e23c9ce3aec0bdb719ce8d4e7136a63dba0b0b2d7bc277de96b500e10cca9f5058b0a8fee0b8f81ce6cfc894db984472c99e65401af29
|
|
7
|
+
data.tar.gz: 9aefe55598d3e63ab69df53c2fbc95ea6697b46b7d1ce5b19909e8a54b6bb346bc460c858d572bfd2c07cc49c05fe12d6a9e1fb2be026ce58efc01aa0b80f879
|
data/README.md
CHANGED
|
@@ -1,103 +1,251 @@
|
|
|
1
1
|
# PageStructuredData
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
|
|
3
|
+
PageStructuredData is a small Rails engine for rendering page-level SEO and social sharing metadata from one page object.
|
|
4
|
+
|
|
5
|
+
It helps Rails applications render:
|
|
6
|
+
|
|
7
|
+
- A `<title>` tag
|
|
8
|
+
- Basic `title`, `description`, and `image` meta tags
|
|
9
|
+
- Open Graph tags
|
|
10
|
+
- Twitter card tags
|
|
11
|
+
- Google-compatible JSON-LD structured data
|
|
12
|
+
- Breadcrumb structured data
|
|
13
|
+
- Article structured data for `BlogPosting` and `NewsArticle`
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- Rails 7.0 or newer
|
|
18
|
+
- Slim 4.1 or newer
|
|
19
|
+
- A Ruby version supported by your Rails version
|
|
8
20
|
|
|
9
21
|
## Installation
|
|
10
|
-
|
|
22
|
+
|
|
23
|
+
Add the gem to your application's Gemfile:
|
|
11
24
|
|
|
12
25
|
```ruby
|
|
13
26
|
gem "page_structured_data"
|
|
14
27
|
```
|
|
15
28
|
|
|
16
|
-
|
|
29
|
+
Then install it:
|
|
30
|
+
|
|
17
31
|
```bash
|
|
18
|
-
|
|
32
|
+
bundle install
|
|
19
33
|
```
|
|
20
34
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
Configure application-wide defaults in an initializer:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
# config/initializers/page_structured_data.rb
|
|
41
|
+
Rails.application.config.after_initialize do
|
|
42
|
+
PageStructuredData.config do |config|
|
|
43
|
+
config.base_app_name = "AwesomestApp"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
24
46
|
```
|
|
25
47
|
|
|
26
|
-
|
|
48
|
+
`base_app_name` is appended to generated page titles.
|
|
27
49
|
|
|
28
|
-
|
|
50
|
+
For example:
|
|
29
51
|
|
|
30
|
-
|
|
52
|
+
```ruby
|
|
53
|
+
PageStructuredData.base_app_name = "AwesomestApp"
|
|
31
54
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
page = PageStructuredData::Page.new(
|
|
56
|
+
title: "Pricing",
|
|
57
|
+
extra_title: "Plans",
|
|
58
|
+
description: "Simple pricing for AwesomestApp"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
page.page_title
|
|
62
|
+
# => "Pricing - Plans - AwesomestApp"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Rendering Meta Tags
|
|
66
|
+
|
|
67
|
+
Render the bundled partial from your application layout:
|
|
68
|
+
|
|
69
|
+
```erb
|
|
70
|
+
<%= render "page_structured_data/meta_tags",
|
|
71
|
+
page: @page_meta,
|
|
72
|
+
default_image_url: image_url("social/default.png") %>
|
|
35
73
|
```
|
|
36
74
|
|
|
37
|
-
|
|
75
|
+
`default_image_url` is optional. It is used when the page object does not provide an image.
|
|
76
|
+
|
|
77
|
+
This partial is only responsible for SEO, social sharing, and structured-data tags. Keep your normal Rails layout tags, such as CSRF, CSP, viewport, and favicon tags, in your application layout.
|
|
38
78
|
|
|
39
|
-
|
|
79
|
+
## Basic Page Metadata
|
|
40
80
|
|
|
41
|
-
|
|
81
|
+
Set `@page_meta` in the controller or view before the layout renders:
|
|
42
82
|
|
|
43
83
|
```ruby
|
|
44
|
-
|
|
45
|
-
|
|
84
|
+
@page_meta = PageStructuredData::Page.new(
|
|
85
|
+
title: "Home",
|
|
86
|
+
extra_title: "Official Page",
|
|
87
|
+
description: "Welcome to my page",
|
|
88
|
+
image: image_url("social/home.png")
|
|
89
|
+
)
|
|
46
90
|
```
|
|
47
91
|
|
|
48
|
-
The
|
|
92
|
+
The generated title is built from:
|
|
49
93
|
|
|
50
|
-
|
|
94
|
+
1. `title`
|
|
95
|
+
2. `extra_title`, when present
|
|
96
|
+
3. breadcrumb titles, when present
|
|
97
|
+
4. `PageStructuredData.base_app_name`, when present
|
|
51
98
|
|
|
52
|
-
|
|
99
|
+
The parts are joined with `" - "`.
|
|
53
100
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
101
|
+
## Breadcrumbs
|
|
102
|
+
|
|
103
|
+
Create breadcrumbs with a hierarchy of page titles and URLs:
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
breadcrumbs = PageStructuredData::Breadcrumbs.new(
|
|
107
|
+
hierarchy: [
|
|
108
|
+
{ title: "Resources", href: resources_url },
|
|
109
|
+
{ title: "Articles", href: resources_articles_url }
|
|
110
|
+
]
|
|
111
|
+
)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Pass the breadcrumbs into the page object:
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
@page_meta = PageStructuredData::Page.new(
|
|
118
|
+
title: "How to Structure Metadata",
|
|
119
|
+
description: "A guide to page metadata and structured data",
|
|
120
|
+
breadcrumb: breadcrumbs
|
|
121
|
+
)
|
|
61
122
|
```
|
|
62
123
|
|
|
63
|
-
|
|
124
|
+
This renders `BreadcrumbList` JSON-LD similar to Google's breadcrumb structured data format.
|
|
125
|
+
|
|
126
|
+
Current compatibility note: when no breadcrumb object is passed, `PageStructuredData::Page` still creates an empty breadcrumb trail for the current page. This is existing behavior and should be considered part of the current public API.
|
|
127
|
+
|
|
128
|
+
## Article Page Types
|
|
129
|
+
|
|
130
|
+
PageStructuredData includes page types for:
|
|
64
131
|
|
|
65
|
-
|
|
132
|
+
- [`BlogPosting`](https://schema.org/BlogPosting)
|
|
133
|
+
- [`NewsArticle`](https://schema.org/NewsArticle)
|
|
66
134
|
|
|
67
|
-
|
|
68
|
-
|
|
135
|
+
Use a page type when the current page represents an article:
|
|
136
|
+
|
|
137
|
+
```ruby
|
|
138
|
+
article_page_type = PageStructuredData::PageTypes::BlogPosting.new(
|
|
139
|
+
headline: @article.title,
|
|
140
|
+
published_at: @article.published_at,
|
|
141
|
+
updated_at: @article.updated_at,
|
|
142
|
+
authors: [
|
|
143
|
+
{
|
|
144
|
+
name: @article.authors.first.name,
|
|
145
|
+
url: @article.authors.first.website
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
images: [
|
|
149
|
+
main_app.url_for(@article.cover_image.variant(:standard))
|
|
150
|
+
]
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
@page_meta = PageStructuredData::Page.new(
|
|
154
|
+
title: @article.title,
|
|
155
|
+
description: @article.summary,
|
|
156
|
+
image: main_app.url_for(@article.cover_image.variant(:standard)),
|
|
157
|
+
breadcrumb: breadcrumbs,
|
|
158
|
+
page_type: article_page_type
|
|
159
|
+
)
|
|
69
160
|
```
|
|
70
161
|
|
|
71
|
-
|
|
162
|
+
For news pages, use `PageStructuredData::PageTypes::NewsArticle` with the same arguments.
|
|
163
|
+
|
|
164
|
+
## API Reference
|
|
165
|
+
|
|
166
|
+
### `PageStructuredData::Page`
|
|
72
167
|
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
|
|
168
|
+
```ruby
|
|
169
|
+
PageStructuredData::Page.new(
|
|
170
|
+
title:,
|
|
171
|
+
description: nil,
|
|
172
|
+
image: nil,
|
|
173
|
+
extra_title: "",
|
|
174
|
+
breadcrumb: nil,
|
|
175
|
+
page_type: nil
|
|
176
|
+
)
|
|
76
177
|
```
|
|
77
178
|
|
|
78
|
-
|
|
179
|
+
Important methods:
|
|
180
|
+
|
|
181
|
+
- `page_title`: returns the composed page title.
|
|
182
|
+
- `json_lds`: returns the JSON-LD script tags for breadcrumbs and page type data.
|
|
79
183
|
|
|
80
|
-
###
|
|
184
|
+
### `PageStructuredData::Breadcrumbs`
|
|
185
|
+
|
|
186
|
+
```ruby
|
|
187
|
+
PageStructuredData::Breadcrumbs.new(
|
|
188
|
+
hierarchy: [
|
|
189
|
+
{ title: "Resources", href: "https://example.com/resources" }
|
|
190
|
+
]
|
|
191
|
+
)
|
|
192
|
+
```
|
|
81
193
|
|
|
82
|
-
|
|
194
|
+
Important methods:
|
|
83
195
|
|
|
84
|
-
|
|
85
|
-
|
|
196
|
+
- `titles`: returns breadcrumb titles.
|
|
197
|
+
- `json_ld(current_page_title:)`: returns a `BreadcrumbList` JSON-LD script tag.
|
|
86
198
|
|
|
87
|
-
|
|
199
|
+
### Article Page Types
|
|
88
200
|
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
201
|
+
```ruby
|
|
202
|
+
PageStructuredData::PageTypes::BlogPosting.new(
|
|
203
|
+
headline:,
|
|
204
|
+
published_at:,
|
|
205
|
+
updated_at:,
|
|
206
|
+
images: [],
|
|
207
|
+
authors: []
|
|
208
|
+
)
|
|
95
209
|
```
|
|
96
210
|
|
|
97
|
-
|
|
211
|
+
```ruby
|
|
212
|
+
PageStructuredData::PageTypes::NewsArticle.new(
|
|
213
|
+
headline:,
|
|
214
|
+
published_at:,
|
|
215
|
+
updated_at:,
|
|
216
|
+
images: [],
|
|
217
|
+
authors: []
|
|
218
|
+
)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
`authors` should be an array of hashes with `:name` and `:url` keys.
|
|
222
|
+
|
|
223
|
+
## Development
|
|
224
|
+
|
|
225
|
+
Run the test suite:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
bundle exec rake test
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Verify the gem can be required:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
ruby -Ilib -e 'require "page_structured_data"; puts PageStructuredData::VERSION'
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Compatibility Policy
|
|
238
|
+
|
|
239
|
+
This gem is used in production applications. Changes should preserve existing public APIs and rendered output unless a breaking change is intentionally released in a major version.
|
|
240
|
+
|
|
241
|
+
Prefer additive APIs and tests that document current behavior before refactoring internals.
|
|
98
242
|
|
|
99
243
|
## Contributing
|
|
100
|
-
|
|
244
|
+
|
|
245
|
+
Bug reports and pull requests are welcome on GitHub.
|
|
246
|
+
|
|
247
|
+
When contributing, please include tests for user-visible behavior and keep changes focused. For compatibility-sensitive behavior, describe the expected impact in the pull request.
|
|
101
248
|
|
|
102
249
|
## License
|
|
250
|
+
|
|
103
251
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: page_structured_data
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jey Geethan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-05-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|