-
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.
Merge pull request #1525 from alphagov/temp-guide-faq
Temp revert to previous FAQPages on Guides
- 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