page_structured_data 1.0.12 → 1.0.13

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: 885b125f1d2fed94a1e0bba7d2c70877f0dba9c5f4ebde59c52f970f2fc4fce4
4
- data.tar.gz: 513764c63a8dae5e609d2e92ea1e99dee3fe0555a3727afa24c3d2afdcc64ffd
3
+ metadata.gz: 8e263a2b3ad541c2b5e72aa79e71d47d72803ddb8a4ac286898e6c6f35105394
4
+ data.tar.gz: 96f01f8fc820456eb69ba5a351f8971022758088d0a5633240c38c7831df43f9
5
5
  SHA512:
6
- metadata.gz: 1e4530a70cf06b4d81cab2322759500bdb29acb31ef8c33846f40d9095cb981c2272feb0fe6c57b6b5c363915e59ab7300071d618799459d2e34317bfc1434e8
7
- data.tar.gz: 6a900ab594f816e1b2edd833a350a15c0837503af68f3efa0a475ac723e05b21bdc66cbad39384c680a2dfab4dfd173137dd9a05f245f236df450e757f162f98
6
+ metadata.gz: 802b70166a18b5475e702822cfb7b0c565c7fc59d8dd5059831261676831e1150c95b8f0e1e11b0de493aa120f3e23f2ddd9a619238ebcdd5f25c8f3920d3d6e
7
+ data.tar.gz: bc818be71ea5d603ac3fb6b84e99dcf79fd76607f3272039cde49d65c772f365d812c0f7d260cdf7beda88762012994ae207b309e7a5dc21b94ab129608e0c9e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ All notable changes to this project are documented here.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 1.0.13 - 2026-05-06
8
+
9
+ - Add `PageStructuredData::PageTypes::Person` for reusable schema.org person values.
10
+ - Accept richer article author values and omit blank nested schema fields.
11
+ - Add page-level `base_app_name` and `render_breadcrumb_json_ld` options.
12
+ - Omit blank description and image meta tags.
13
+
7
14
  ## 1.0.12 - 2026-05-06
8
15
 
9
16
  - Add reusable interaction statistics for article-like page types.
data/README.md CHANGED
@@ -16,6 +16,7 @@ It helps Rails applications render:
16
16
  - Article structured data for `BlogPosting` and `NewsArticle`
17
17
  - Discussion forum post structured data
18
18
  - Interaction statistics for public engagement counts
19
+ - Reusable Person structured data
19
20
  - Organization and WebSite structured data
20
21
 
21
22
  ## Requirements
@@ -144,6 +145,7 @@ PageStructuredData includes page types for:
144
145
  - [`BlogPosting`](https://schema.org/BlogPosting)
145
146
  - [`NewsArticle`](https://schema.org/NewsArticle)
146
147
  - [`DiscussionForumPosting`](https://schema.org/DiscussionForumPosting)
148
+ - [`Person`](https://schema.org/Person)
147
149
  - [`Organization`](https://schema.org/Organization)
148
150
  - [`WebSite`](https://schema.org/WebSite)
149
151
 
@@ -277,10 +279,15 @@ PageStructuredData::Page.new(
277
279
  page_type: nil,
278
280
  page_types: nil,
279
281
  canonical_url: nil,
280
- fallback_image: nil
282
+ fallback_image: nil,
283
+ base_app_name: nil,
284
+ render_breadcrumb_json_ld: nil
281
285
  )
282
286
  ```
283
287
 
288
+ `base_app_name` overrides `PageStructuredData.base_app_name` for one page. Pass an empty string to suppress the global app name for a specific page.
289
+ `render_breadcrumb_json_ld` can be set to `true` or `false` for one page. Leave it as `nil` to use the global `PageStructuredData.render_default_breadcrumb_json_ld` behavior for generated default breadcrumbs. Explicit breadcrumb objects still render when the global default is disabled unless the page sets `render_breadcrumb_json_ld: false`.
290
+
284
291
  Important methods:
285
292
 
286
293
  - `page_title`: returns the composed page title.
@@ -341,7 +348,7 @@ PageStructuredData::PageTypes::NewsArticle.new(
341
348
  )
342
349
  ```
343
350
 
344
- `authors` should be an array of hashes with `:name` and `:url` keys.
351
+ `authors` can be an array of hashes, `PageStructuredData::PageTypes::Person` objects, or other objects that respond to `to_h`.
345
352
  `image` is a convenience option for one image URL. Use `images` when passing multiple image URLs.
346
353
  `text` is an alias for `article_body`.
347
354
  `interaction_statistics` should be an array of `PageStructuredData::PageTypes::InteractionStatistic` objects or schema-compatible hashes.
@@ -393,6 +400,30 @@ Important methods:
393
400
 
394
401
  - `to_h`: returns a structured hash for `InteractionCounter` JSON-LD.
395
402
 
403
+ ### Person
404
+
405
+ ```ruby
406
+ PageStructuredData::PageTypes::Person.new(
407
+ name:,
408
+ url: nil,
409
+ image: nil,
410
+ same_as: []
411
+ )
412
+ ```
413
+
414
+ Use `Person` for article authors, organization founders, and other schema.org person values:
415
+
416
+ ```ruby
417
+ author = PageStructuredData::PageTypes::Person.new(
418
+ name: "Jane Doe",
419
+ url: "https://example.com/jane"
420
+ )
421
+ ```
422
+
423
+ Important methods:
424
+
425
+ - `to_h`: returns a compact structured hash for `Person` JSON-LD.
426
+
396
427
  ### Organization Page Type
397
428
 
398
429
  ```ruby
@@ -4,11 +4,11 @@ module PageStructuredData
4
4
  # Basic page metadata for any page
5
5
  class Page
6
6
  attr_reader :title, :description, :image, :extra_title, :breadcrumb, :page_type, :page_types, :canonical_url,
7
- :fallback_image
7
+ :fallback_image, :base_app_name, :render_breadcrumb_json_ld
8
8
 
9
9
  def initialize(title:, description: nil, image: nil, # rubocop:disable Metrics/ParameterLists
10
10
  extra_title: '', breadcrumb: nil, page_type: nil, page_types: nil, canonical_url: nil,
11
- fallback_image: nil)
11
+ fallback_image: nil, base_app_name: nil, render_breadcrumb_json_ld: nil)
12
12
  @title = title
13
13
  @description = description
14
14
  @image = image
@@ -18,6 +18,8 @@ module PageStructuredData
18
18
  @page_types = page_types
19
19
  @canonical_url = canonical_url
20
20
  @fallback_image = fallback_image
21
+ @base_app_name = base_app_name
22
+ @render_breadcrumb_json_ld = render_breadcrumb_json_ld
21
23
  end
22
24
 
23
25
  def title_with_hierarchies
@@ -28,8 +30,8 @@ module PageStructuredData
28
30
 
29
31
  def page_title
30
32
  result = title_with_hierarchies.join(separator)
31
- if base_app_name.present?
32
- result += separator + base_app_name
33
+ if resolved_base_app_name.present?
34
+ result += separator + resolved_base_app_name
33
35
  end
34
36
  result
35
37
  end
@@ -52,13 +54,22 @@ module PageStructuredData
52
54
  end
53
55
 
54
56
  def breadcrumb_json_ld
57
+ return if render_breadcrumb_json_ld == false
55
58
  return breadcrumb.json_ld(current_page_title: title) if breadcrumb.present?
56
- return unless PageStructuredData.render_default_breadcrumb_json_ld
59
+ return unless render_breadcrumb_json_ld?
57
60
 
58
61
  Breadcrumbs.new.json_ld(current_page_title: title)
59
62
  end
60
63
 
61
- def base_app_name
64
+ def render_breadcrumb_json_ld?
65
+ return render_breadcrumb_json_ld unless render_breadcrumb_json_ld.nil?
66
+
67
+ PageStructuredData.render_default_breadcrumb_json_ld
68
+ end
69
+
70
+ def resolved_base_app_name
71
+ return base_app_name unless base_app_name.nil?
72
+
62
73
  PageStructuredData.base_app_name
63
74
  end
64
75
 
@@ -4,6 +4,8 @@ module PageStructuredData
4
4
  module PageTypes
5
5
  # Shared structured data for schema.org article-like page types.
6
6
  class Article
7
+ include SchemaNode
8
+
7
9
  attr_reader :headline, :images, :published_at, :updated_at, :authors, :article_body, :url,
8
10
  :interaction_statistics, :likes_count, :comments_count, :shares_count
9
11
 
@@ -30,13 +32,7 @@ module PageStructuredData
30
32
  image: images,
31
33
  datePublished: published_at,
32
34
  dateModified: updated_at,
33
- author: authors.map do |author|
34
- {
35
- '@type': 'Person',
36
- name: author[:name],
37
- url: author[:url],
38
- }
39
- end,
35
+ author: authors.map { |author| author_to_h(author) },
40
36
  }
41
37
 
42
38
  node[:articleBody] = article_body if article_body.present?
@@ -60,6 +56,18 @@ module PageStructuredData
60
56
  raise NotImplementedError, "#{self.class.name} must define #schema_type"
61
57
  end
62
58
 
59
+ def author_to_h(author)
60
+ return object_to_h(author) if author.respond_to?(:to_h) && !author.is_a?(Hash)
61
+
62
+ compact_node(
63
+ '@type': 'Person',
64
+ name: author[:name] || author['name'],
65
+ url: author[:url] || author['url'],
66
+ image: author[:image] || author['image'],
67
+ sameAs: author[:same_as] || author[:sameAs] || author['same_as'] || author['sameAs']
68
+ )
69
+ end
70
+
63
71
  def interaction_statistics_to_h
64
72
  @interaction_statistics_to_h ||= all_interaction_statistics.map do |interaction_statistic|
65
73
  if interaction_statistic.respond_to?(:to_h)
@@ -4,6 +4,8 @@ module PageStructuredData
4
4
  module PageTypes
5
5
  # schema.org InteractionCounter structured data.
6
6
  class InteractionStatistic
7
+ include SchemaNode
8
+
7
9
  ACTION_TYPES = {
8
10
  like: 'LikeAction',
9
11
  likes: 'LikeAction',
@@ -34,15 +36,12 @@ module PageStructuredData
34
36
  end
35
37
 
36
38
  def to_h
37
- node = {
39
+ compact_node(
38
40
  '@type': 'InteractionCounter',
39
41
  interactionType: interaction_type_to_h,
40
42
  userInteractionCount: user_interaction_count,
41
- }
42
-
43
- node[:interactionService] = object_to_h(interaction_service) if interaction_service.present?
44
-
45
- node
43
+ interactionService: object_to_h(interaction_service)
44
+ )
46
45
  end
47
46
 
48
47
  private
@@ -54,12 +53,6 @@ module PageStructuredData
54
53
 
55
54
  { '@type': type }
56
55
  end
57
-
58
- def object_to_h(object)
59
- return object.to_h if object.respond_to?(:to_h)
60
-
61
- object
62
- end
63
56
  end
64
57
  end
65
58
  end
@@ -4,6 +4,8 @@ module PageStructuredData
4
4
  module PageTypes
5
5
  # Organization structured data for a page
6
6
  class Organization
7
+ include SchemaNode
8
+
7
9
  attr_reader :name, :url, :description, :logo, :same_as, :parent_organization, :founder
8
10
 
9
11
  def initialize(name:, url:, description: nil, logo: nil, same_as: [], parent_organization: nil, founder: nil)
@@ -11,33 +13,23 @@ module PageStructuredData
11
13
  @url = url
12
14
  @description = description
13
15
  @logo = logo
14
- @same_as = same_as
16
+ @same_as = Array(same_as)
15
17
  @parent_organization = parent_organization
16
18
  @founder = founder
17
19
  end
18
20
 
19
21
  def to_h # rubocop:disable Metrics/MethodLength
20
- node = {
22
+ compact_node(
21
23
  '@context': 'https://schema.org',
22
24
  '@type': 'Organization',
23
- }
24
-
25
- node[:name] = name
26
- node[:url] = url
27
- node[:description] = description if description.present?
28
- node[:logo] = logo if logo.present?
29
- node[:sameAs] = same_as if same_as.present?
30
- node[:founder] = founder_to_h if founder.present?
31
-
32
- if parent_organization.present?
33
- node[:parentOrganization] = {
34
- '@type': 'Organization',
35
- name: parent_organization[:name],
36
- url: parent_organization[:url],
37
- }
38
- end
39
-
40
- node
25
+ name: name,
26
+ url: url,
27
+ description: description,
28
+ logo: logo,
29
+ sameAs: same_as,
30
+ founder: object_to_h(founder),
31
+ parentOrganization: parent_organization_to_h
32
+ )
41
33
  end
42
34
 
43
35
  def json_ld
@@ -50,10 +42,15 @@ module PageStructuredData
50
42
 
51
43
  private
52
44
 
53
- def founder_to_h
54
- return founder.to_h if founder.respond_to?(:to_h)
45
+ def parent_organization_to_h
46
+ return object_to_h(parent_organization) if parent_organization.respond_to?(:to_h) && !parent_organization.is_a?(Hash)
47
+ return unless parent_organization.present?
55
48
 
56
- founder
49
+ compact_node(
50
+ '@type': 'Organization',
51
+ name: parent_organization[:name] || parent_organization['name'],
52
+ url: parent_organization[:url] || parent_organization['url']
53
+ )
57
54
  end
58
55
  end
59
56
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PageStructuredData
4
+ module PageTypes
5
+ # schema.org Person structured data.
6
+ class Person
7
+ include SchemaNode
8
+
9
+ attr_reader :name, :url, :image, :same_as
10
+
11
+ def initialize(name:, url: nil, image: nil, same_as: [])
12
+ @name = name
13
+ @url = url
14
+ @image = image
15
+ @same_as = Array(same_as)
16
+ end
17
+
18
+ def to_h
19
+ compact_node(
20
+ '@type': 'Person',
21
+ name: name,
22
+ url: url,
23
+ image: image,
24
+ sameAs: same_as
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PageStructuredData
4
+ module PageTypes
5
+ # Shared helpers for schema.org hash values.
6
+ module SchemaNode
7
+ private
8
+
9
+ def compact_node(node)
10
+ node.each_with_object({}) do |(key, value), compacted|
11
+ next if blank_schema_value?(value)
12
+
13
+ compacted[key] = value
14
+ end
15
+ end
16
+
17
+ def object_to_h(object)
18
+ return object.to_h if object.respond_to?(:to_h)
19
+
20
+ object
21
+ end
22
+
23
+ def blank_schema_value?(value)
24
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -4,6 +4,8 @@ module PageStructuredData
4
4
  module PageTypes
5
5
  # WebSite structured data for a page
6
6
  class WebSite
7
+ include SchemaNode
8
+
7
9
  attr_reader :name, :url, :description, :publisher, :potential_action
8
10
 
9
11
  def initialize(name:, url:, description: nil, publisher: nil, potential_action: nil)
@@ -15,18 +17,15 @@ module PageStructuredData
15
17
  end
16
18
 
17
19
  def to_h
18
- node = {
20
+ compact_node(
19
21
  '@context': 'https://schema.org',
20
22
  '@type': 'WebSite',
21
23
  name: name,
22
24
  url: url,
23
- }
24
-
25
- node[:description] = description if description.present?
26
- node[:publisher] = publisher_to_h if publisher.present?
27
- node[:potentialAction] = potential_action if potential_action.present?
28
-
29
- node
25
+ description: description,
26
+ publisher: object_to_h(publisher),
27
+ potentialAction: object_to_h(potential_action)
28
+ )
30
29
  end
31
30
 
32
31
  def json_ld
@@ -37,13 +36,6 @@ module PageStructuredData
37
36
  )
38
37
  end
39
38
 
40
- private
41
-
42
- def publisher_to_h
43
- return publisher.to_h if publisher.respond_to?(:to_h)
44
-
45
- publisher
46
- end
47
39
  end
48
40
  end
49
41
  end
@@ -11,16 +11,28 @@
11
11
  <% end %>
12
12
 
13
13
  <meta name="title" content="<%= title %>">
14
+ <% if description.present? %>
14
15
  <meta name="description" content="<%= description %>">
16
+ <% end %>
17
+ <% if image.present? %>
15
18
  <meta name="image" content="<%= image %>">
19
+ <% end %>
16
20
 
17
21
  <meta property="og:title" content="<%= title %>">
22
+ <% if description.present? %>
18
23
  <meta property="og:description" content="<%= description %>">
24
+ <% end %>
25
+ <% if image.present? %>
19
26
  <meta property="og:image" content="<%= image %>">
27
+ <% end %>
20
28
 
21
29
  <meta name="twitter:card" content="summary_large_image">
22
30
  <meta name="twitter:title" content="<%= title %>">
31
+ <% if description.present? %>
23
32
  <meta name="twitter:description" content="<%= description %>">
33
+ <% end %>
34
+ <% if image.present? %>
24
35
  <meta name="twitter:image" content="<%= image %>">
36
+ <% end %>
25
37
 
26
38
  <%= page&.json_lds&.html_safe %>
@@ -1,3 +1,3 @@
1
1
  module PageStructuredData
2
- VERSION = "1.0.12"
2
+ VERSION = "1.0.13"
3
3
  end
@@ -2,6 +2,8 @@ require "page_structured_data/version"
2
2
  require "page_structured_data/engine"
3
3
  require_relative "../app/src/page_structured_data/anchors"
4
4
  require_relative "../app/src/page_structured_data/breadcrumbs"
5
+ require_relative "../app/src/page_structured_data/page_types/schema_node"
6
+ require_relative "../app/src/page_structured_data/page_types/person"
5
7
  require_relative "../app/src/page_structured_data/page_types/interaction_statistic"
6
8
  require_relative "../app/src/page_structured_data/page_types/article"
7
9
  require_relative "../app/src/page_structured_data/page_types/blog_posting"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_structured_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jey Geethan
@@ -32,8 +32,8 @@ dependencies:
32
32
  version: '9.0'
33
33
  description: PageStructuredData gives Rails applications a small page object and view
34
34
  partial for rendering page titles, basic meta tags, Open Graph tags, Twitter card
35
- tags, breadcrumb JSON-LD, article and forum post JSON-LD, Organization JSON-LD,
36
- WebSite JSON-LD, and public interaction statistics.
35
+ tags, breadcrumb JSON-LD, article and forum post JSON-LD, Person, Organization,
36
+ and WebSite JSON-LD, and public interaction statistics.
37
37
  email:
38
38
  - opensource@rocketapex.com
39
39
  executables: []
@@ -53,6 +53,8 @@ files:
53
53
  - app/src/page_structured_data/page_types/interaction_statistic.rb
54
54
  - app/src/page_structured_data/page_types/news_article.rb
55
55
  - app/src/page_structured_data/page_types/organization.rb
56
+ - app/src/page_structured_data/page_types/person.rb
57
+ - app/src/page_structured_data/page_types/schema_node.rb
56
58
  - app/src/page_structured_data/page_types/web_site.rb
57
59
  - app/views/page_structured_data/_meta_tags.html.erb
58
60
  - config/routes.rb