govuk_publishing_components 10.0.0 → 10.1.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: eedc7db41f2d178ff05e1905a8eb380dd37140a8a0ed8c8e35adce4843820dcd
4
- data.tar.gz: 02b05d72c20971d88bff48a36c42a910e8bf9882c4e9a88d827a9d4a5b399ae0
3
+ metadata.gz: 79208a2aa5fe09127a376f0b1dfbe4a703c03c738b06cee07b04b0a41c2e5527
4
+ data.tar.gz: 3a8b99c01ab4b32e6bf18beddfaf798043b83b967d1d93d6be3775ae5932d0e7
5
5
  SHA512:
6
- metadata.gz: 61fd9a082433a65c367b1e9f56b50d417bfcf1b1479e0830c2be22d7b63af18e91b923058be1d057e104a5bd7587b1e4d59a5887325f116712fa714729431341
7
- data.tar.gz: 97c87c351d487aec51b61d9a9e2f6a696d21c6bf219ef94340be088d6f5e368b1692bcab27ecf6e204208d108188c3c7c46fd74549a13c679ee3012375c79e3b
6
+ metadata.gz: 5602b8c9c50df8e12d28bba3a5ee08a1141cdc67892700745610ac452b8380a0310c51a1b395f91e7273d9d7b7913cfd38ef448a2a229e3e8ea2dcea125ba9ea
7
+ data.tar.gz: c3dd7d269ed451de61be94db9667121ab96211de00497f197050d9f4d8a25ba21775a4824bd0eea30c83764d5da8273aab87903844fcb2bc554ceb132546c4e5
@@ -5,6 +5,7 @@ module GovukPublishingComponents
5
5
 
6
6
  def initialize(page)
7
7
  @page = page
8
+ @pages = {}
8
9
  end
9
10
 
10
11
  def structured_data
@@ -69,20 +70,21 @@ module GovukPublishingComponents
69
70
  end
70
71
 
71
72
  def is_part_of
72
- return {} unless linked_step_by_steps.any?
73
+ return {} unless step_by_step_schemas.any? || document_collections.any?
74
+
73
75
  {
74
- "isPartOf" => step_by_step_schemas
76
+ "isPartOf" => document_collections + step_by_step_schemas
75
77
  }
76
78
  end
77
79
 
78
- def linked_step_by_steps
80
+ def step_by_step_schemas
79
81
  # We could include `related_to_step_navs` eventually too, but initially
80
82
  # link to those that we render in the "step_by_step_nav_related" component
81
- @step_by_steps ||= page.content_item.dig("links", "part_of_step_navs").to_a
83
+ @step_by_steps ||= fetch_step_by_step_schemas
82
84
  end
83
85
 
84
- def step_by_step_schemas
85
- linked_step_by_steps.map do |step_by_step|
86
+ def fetch_step_by_step_schemas
87
+ page.content_item.dig("links", "part_of_step_navs").to_a.map do |step_by_step|
86
88
  step_by_step_page = linked_page(step_by_step)
87
89
  structured_data = HowToSchema.new(step_by_step_page.canonical_url).structured_data
88
90
 
@@ -100,18 +102,23 @@ module GovukPublishingComponents
100
102
  end
101
103
 
102
104
  def has_part
103
- return {} unless collection_pages.any?
105
+ return {} unless collection_pages("documents").any?
104
106
  {
105
- "hasPart" => collection_pages.map { |document| HasPartSchema.new(document).structured_data }
107
+ "hasPart" => collection_pages("documents").map { |document| HasPartSchema.new(document).structured_data }
106
108
  }
107
109
  end
108
110
 
109
- def collection_pages
110
- @pages ||= fetch_collection_pages
111
+ def document_collections
112
+ @document_collections ||= collection_pages("document_collections")
113
+ .map { |document| IsPartOfSchema.new(document).structured_data }
114
+ end
115
+
116
+ def collection_pages(linked_type)
117
+ @pages[linked_type] ||= fetch_collection_pages(linked_type)
111
118
  end
112
119
 
113
- def fetch_collection_pages
114
- page.content_item.dig("links", "documents").to_a.map { |document| document["web_url"] }
120
+ def fetch_collection_pages(linked_type)
121
+ page.content_item.dig("links", linked_type).to_a.map { |document| document["web_url"] }
115
122
  end
116
123
 
117
124
  def about
@@ -0,0 +1,18 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class IsPartOfSchema
4
+ def initialize(is_part_of_url)
5
+ @is_part_of_url = is_part_of_url
6
+ end
7
+
8
+ def structured_data
9
+ # http://schema.org/isPartOf - minimal
10
+ {
11
+ "@context" => "http://schema.org",
12
+ "@type" => "CreativeWork",
13
+ "sameAs" => @is_part_of_url
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -2,6 +2,7 @@ require 'govuk_publishing_components/presenters/machine_readable/page'
2
2
  require 'govuk_publishing_components/presenters/machine_readable/article_schema'
3
3
  require 'govuk_publishing_components/presenters/machine_readable/how_to_schema'
4
4
  require 'govuk_publishing_components/presenters/machine_readable/has_part_schema'
5
+ require 'govuk_publishing_components/presenters/machine_readable/is_part_of_schema'
5
6
  require 'govuk_publishing_components/presenters/machine_readable/news_article_schema'
6
7
  require 'govuk_publishing_components/presenters/machine_readable/organisation_schema'
7
8
  require 'govuk_publishing_components/presenters/machine_readable/person_schema'
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = '10.0.0'.freeze
2
+ VERSION = '10.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0
4
+ version: 10.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -590,6 +590,7 @@ files:
590
590
  - lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
591
591
  - lib/govuk_publishing_components/presenters/machine_readable/has_part_schema.rb
592
592
  - lib/govuk_publishing_components/presenters/machine_readable/how_to_schema.rb
593
+ - lib/govuk_publishing_components/presenters/machine_readable/is_part_of_schema.rb
593
594
  - lib/govuk_publishing_components/presenters/machine_readable/news_article_schema.rb
594
595
  - lib/govuk_publishing_components/presenters/machine_readable/organisation_schema.rb
595
596
  - lib/govuk_publishing_components/presenters/machine_readable/page.rb