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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb34fae60cc0d7ec3b9d686d8a5977d515fd29784d6beee5b7b63af55a902555
4
- data.tar.gz: 8e81d0952b1e139cbd1f74d3a6f6518225e7d9c5da6be62e8c87e7f8a1c57094
3
+ metadata.gz: 8e6e417c38d0a25d8e3270315eb9d98434eb9dbc93e7860667a96e457b94bfa9
4
+ data.tar.gz: e3f2b717b5b01cd49c90675fb1a74199b89492c298fa93474ad75772530edf32
5
5
  SHA512:
6
- metadata.gz: 8bddeabf6322a0942c71a0dde014be7a1030d43d16d53fed97fd8fad206681ae3060ed06a7a19885bdcace26a215813e0d190fb5e72edd7ab9d0127fa90b683c
7
- data.tar.gz: d55d272089d34357730ae7c079bb428b53de64c0c7aa9b7745589ca7156b07d4e3d1ef7d96921f44be075d1b7ae2337fc0ae56f95f498ebd6ef13eec6502e740
6
+ metadata.gz: 80bc6fed7640148b6f7e23c9ce3aec0bdb719ce8d4e7136a63dba0b0b2d7bc277de96b500e10cca9f5058b0a8fee0b8f81ce6cfc894db984472c99e65401af29
7
+ data.tar.gz: 9aefe55598d3e63ab69df53c2fbc95ea6697b46b7d1ce5b19909e8a54b6bb346bc460c858d572bfd2c07cc49c05fe12d6a9e1fb2be026ce58efc01aa0b80f879
data/README.md CHANGED
@@ -1,103 +1,251 @@
1
1
  # PageStructuredData
2
- Use this gem to churn out meta tags for your rails webpages. This also renders meta tags for the following:
3
- 1. Page `<title>` tag with proper hyphenation when used with breadcrumbs
4
- 2. Basic `<meta>` tags
5
- 2. Twitter meta tags
6
- 3. Open graph meta tags
7
- 4. Google Schema JSON-LD `<script>` tags
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
- Add this line to your application's Gemfile:
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
- And then execute:
29
+ Then install it:
30
+
17
31
  ```bash
18
- $ bundle
32
+ bundle install
19
33
  ```
20
34
 
21
- Or install it yourself as:
22
- ```bash
23
- $ gem install page_structured_data
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
- ## Usage
48
+ `base_app_name` is appended to generated page titles.
27
49
 
28
- ### Layouts
50
+ For example:
29
51
 
30
- Add the following in your layout to include the basic meta tags by default
52
+ ```ruby
53
+ PageStructuredData.base_app_name = "AwesomestApp"
31
54
 
32
- ```erbruby
33
- <%= render 'page_structured_data/meta_tags', page: @page_meta,
34
- default_image_url: image_url('<path_to_default_image>') %>
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
- Note: This doesn't include csrf or any other security or viewport related meta tags.
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
- ### Views
79
+ ## Basic Page Metadata
40
80
 
41
- In your views, please define the `@page_meta` as follows
81
+ Set `@page_meta` in the controller or view before the layout renders:
42
82
 
43
83
  ```ruby
44
- <% @page_meta = PageStructuredData::Page.new(title: 'Home', extra_title: "Official Page",
45
- description: 'Welcome to my Page') %>
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 instance variable will be used in the layout to create proper meta tags. Most attributes are self explanatory. `extra_title` is used to append to the title.
92
+ The generated title is built from:
49
93
 
50
- ### Config
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
- Configure the application wide settings as follows:
99
+ The parts are joined with `" - "`.
53
100
 
54
- ```erbruby
55
- # config/initializers/page_structured_data.rb
56
- Rails.application.config.after_initialize do
57
- PageStructuredData.config do |config|
58
- config.base_app_name = 'AwesomestApp' # or use any application constant as this is called after_initialize
59
- end
60
- end
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
- ### Breadcrumbs
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
- Create a list of breadcrumbs like this:
132
+ - [`BlogPosting`](https://schema.org/BlogPosting)
133
+ - [`NewsArticle`](https://schema.org/NewsArticle)
66
134
 
67
- ```erbruby
68
- <% breadcrumb = PageStructuredData::Breadcrumbs.new(hierarchy: [{ title: 'Resources', href: resources_url }, { title: 'Articles', href: resources_articles_url }]) %>
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
- And include it in the `Page.new` as:
162
+ For news pages, use `PageStructuredData::PageTypes::NewsArticle` with the same arguments.
163
+
164
+ ## API Reference
165
+
166
+ ### `PageStructuredData::Page`
72
167
 
73
- ```erbruby
74
- <% @page_meta = PageStructuredData::Page.new(title: 'Home', extra_title: "Official Page",
75
- description: 'Welcome to my Page', breadcrumb: breadcrumb) %>
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
- This will create a JSON+LD breadcrumbs similar to [Breadcrumbs](https://developers.google.com/search/docs/appearance/structured-data/breadcrumb)
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
- ### PageTypes
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
- Currently this gem supports the following page types:
194
+ Important methods:
83
195
 
84
- * [BlogPosting](https://schema.org/BlogPosting)
85
- * [NewsArticle](https://schema.org/NewsArticle)
196
+ - `titles`: returns breadcrumb titles.
197
+ - `json_ld(current_page_title:)`: returns a `BreadcrumbList` JSON-LD script tag.
86
198
 
87
- To use these, it is similar to breadcrumbs: include them in `Page.new` and it the json+ld will be automatically included.
199
+ ### Article Page Types
88
200
 
89
- ```erbruby
90
- <% article_page_type = PageStructuredData::PageTypes::BlogPosting.new(headline: @article.title, published_at: @article.published_at,
91
- updated_at: @article.updated_at, authors: [name: @article.authors.first.name, url: @article.authors.first.website],
92
- images: [main_app.url_for(@article.cover_image.variant(:standard))]) %>
93
- <% @page_meta = PageStructuredData::Page.new(title: 'Home', extra_title: "Official Page",
94
- description: 'Welcome to my Page', page_type: article_page_type) %>
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
- Just replace BlogPosting class with the other type for other page types.
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
- Please raise a PR to be validated and merged.
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).
@@ -1,3 +1,6 @@
1
+ require "rails"
2
+ require "action_dispatch/railtie"
3
+
1
4
  module PageStructuredData
2
5
  class Engine < ::Rails::Engine
3
6
  isolate_namespace PageStructuredData
@@ -1,3 +1,3 @@
1
1
  module PageStructuredData
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
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.1
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: 2025-12-30 00:00:00.000000000 Z
11
+ date: 2026-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails