-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temp revert to previous FAQPages on Guides
This is a temporary reversion to the original implementation of FAQPage schemas on Guides. We're running user research next week, and want to use this version's Google results. If the research goes well, we'll make a further decision then whether to roll this into the standard implementation. It was [originally implemented in govuk_publishing_components](alphagov/govuk_publishing_components#1087) but I don't want to revert it in publishing components yet because: - Answers also use that implementation, and I don't want to mess with them right now - This version is temporary until 31/10/2019 when we'll decide what to do This version of the schema includes the entirety of a guide's content in the FAQPage schema on the first chapter. The subsequent chapters do not include an FAQPage schema to avoid duplicating rich results (but do include the Article schema).
- Loading branch information
Showing
3 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
app/presenters/machine_readable/guide_faq_page_schema_presenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
module MachineReadable | ||
class GuideFaqPageSchemaPresenter | ||
attr_reader :guide | ||
|
||
def initialize(guide) | ||
@guide = guide | ||
end | ||
|
||
def structured_data | ||
# http://schema.org/FAQPage | ||
{ | ||
"@context" => "http://schema.org", | ||
"@type" => "FAQPage", | ||
"headline" => guide.title, | ||
"description" => guide.description, | ||
"publisher" => { | ||
"@type" => "Organization", | ||
"name" => "GOV.UK", | ||
"url" => "https://www.gov.uk", | ||
"logo" => { | ||
"@type" => "ImageObject", | ||
"url" => logo_url, | ||
}, | ||
}, | ||
} | ||
.merge(main_entity) | ||
end | ||
|
||
private | ||
|
||
def main_entity | ||
{ | ||
"mainEntity" => questions_and_answers, | ||
} | ||
end | ||
|
||
def questions_and_answers | ||
guide.parts.each_with_index.map do |part, index| | ||
part_url = part_url(part, index) | ||
|
||
{ | ||
"@type" => "Question", | ||
"name" => part["title"], | ||
"url" => part_url, | ||
"acceptedAnswer" => { | ||
"@type" => "Answer", | ||
"url" => part_url, | ||
"text" => part["body"], | ||
}, | ||
} | ||
end | ||
end | ||
|
||
def part_url(part, index) | ||
if index.zero? | ||
guide_url | ||
else | ||
guide_url + "/" + part["slug"] | ||
end | ||
end | ||
|
||
def guide_url | ||
Plek.new.website_root + guide.base_path | ||
end | ||
|
||
def logo_url | ||
image_url("govuk_publishing_components/govuk-logo.png") | ||
end | ||
|
||
def image_url(image_file) | ||
ActionController::Base.helpers.asset_url(image_file, type: :image) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters