govuk_publishing_components 20.0.0 → 20.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/govuk_publishing_components/components/docs/machine_readable_metadata.yml +15 -0
- data/lib/govuk_publishing_components/presenters/machine_readable/faq_page_schema.rb +52 -0
- data/lib/govuk_publishing_components/presenters/machine_readable/page.rb +4 -0
- data/lib/govuk_publishing_components/presenters/schema_org.rb +4 -1
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70e1e7a68a80183757a98e24a3a4c9c62cb7b915574e99213f52bbe7363368a2
|
4
|
+
data.tar.gz: 7bab5f6f55fe885de0fe39090d419c5d3816f8bf162b1ae9b9cb739a07465ced
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93bebe89425509dfb139678e9031cba30fcbae81c332c7942212ba020289704546551ec10ec470f57e072c7f31803f4ea03c3934797b73fc50f6eb34c055e580
|
7
|
+
data.tar.gz: 16f8ea19a174281ca1c19f9b135c439e5b64c0dfd3dfd372b5761beccd3f3d73ebce5342dc2054435b5e6827355bc96098a77b3c34bfc8af07d38afef638c534
|
@@ -41,6 +41,21 @@ examples:
|
|
41
41
|
details: {}
|
42
42
|
schema: :article
|
43
43
|
body: "Some other body"
|
44
|
+
a_guide:
|
45
|
+
data:
|
46
|
+
content_item:
|
47
|
+
title: "How to train your dragon"
|
48
|
+
base_path: "/how-to-train-your-dragon"
|
49
|
+
details:
|
50
|
+
parts:
|
51
|
+
- slug: overview
|
52
|
+
body: A thing on how to train scaly beasts
|
53
|
+
title: Overview
|
54
|
+
- slug: treating-injuries
|
55
|
+
body: Get to know a good blacksmith
|
56
|
+
title: Treating injuries
|
57
|
+
schema: :faq
|
58
|
+
canonical_url: https://www.gov.uk/how-to-train-your-dragon
|
44
59
|
person_schema:
|
45
60
|
data:
|
46
61
|
content_item:
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module GovukPublishingComponents
|
2
|
+
module Presenters
|
3
|
+
class FaqPageSchema
|
4
|
+
attr_reader :page
|
5
|
+
|
6
|
+
def initialize(page)
|
7
|
+
@page = page
|
8
|
+
end
|
9
|
+
|
10
|
+
def structured_data
|
11
|
+
# http://schema.org/FAQPage
|
12
|
+
data = CreativeWorkSchema.new(@page).structured_data
|
13
|
+
.merge(main_entity)
|
14
|
+
data["@type"] = "FAQPage"
|
15
|
+
data
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def main_entity
|
21
|
+
{
|
22
|
+
"mainEntity" => questions_and_answers
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def questions_and_answers
|
27
|
+
page.parts.each_with_index.map do |part, index|
|
28
|
+
part_url = part_url(part, index)
|
29
|
+
|
30
|
+
{
|
31
|
+
"@type" => "Question",
|
32
|
+
"name" => part['title'],
|
33
|
+
"url" => part_url,
|
34
|
+
"acceptedAnswer" => {
|
35
|
+
"@type" => "Answer",
|
36
|
+
"url" => part_url,
|
37
|
+
"text" => part['body']
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def part_url(part, index)
|
44
|
+
if index.zero?
|
45
|
+
page.canonical_url
|
46
|
+
else
|
47
|
+
page.canonical_url + "/" + part["slug"]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
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/creative_work_schema'
|
4
|
+
require 'govuk_publishing_components/presenters/machine_readable/faq_page_schema'
|
4
5
|
require 'govuk_publishing_components/presenters/machine_readable/has_part_schema'
|
5
6
|
require 'govuk_publishing_components/presenters/machine_readable/is_part_of_schema'
|
6
7
|
require 'govuk_publishing_components/presenters/machine_readable/news_article_schema'
|
@@ -19,7 +20,9 @@ module GovukPublishingComponents
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def structured_data
|
22
|
-
if page.schema == :
|
23
|
+
if page.schema == :faq
|
24
|
+
FaqPageSchema.new(page).structured_data
|
25
|
+
elsif page.schema == :article
|
23
26
|
ArticleSchema.new(page).structured_data
|
24
27
|
elsif page.schema == :news_article
|
25
28
|
NewsArticleSchema.new(page).structured_data
|
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: 20.
|
4
|
+
version: 20.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -667,6 +667,7 @@ files:
|
|
667
667
|
- lib/govuk_publishing_components/presenters/image_card_helper.rb
|
668
668
|
- lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
|
669
669
|
- lib/govuk_publishing_components/presenters/machine_readable/creative_work_schema.rb
|
670
|
+
- lib/govuk_publishing_components/presenters/machine_readable/faq_page_schema.rb
|
670
671
|
- lib/govuk_publishing_components/presenters/machine_readable/has_part_schema.rb
|
671
672
|
- lib/govuk_publishing_components/presenters/machine_readable/is_part_of_schema.rb
|
672
673
|
- lib/govuk_publishing_components/presenters/machine_readable/news_article_schema.rb
|