diff --git a/app/presenters/machine_readable/guide_faq_page_schema_presenter.rb b/app/presenters/machine_readable/guide_faq_page_schema_presenter.rb new file mode 100644 index 000000000..64c7bec6f --- /dev/null +++ b/app/presenters/machine_readable/guide_faq_page_schema_presenter.rb @@ -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 diff --git a/app/views/content_items/guide.html.erb b/app/views/content_items/guide.html.erb index 1924dab20..db132ad49 100644 --- a/app/views/content_items/guide.html.erb +++ b/app/views/content_items/guide.html.erb @@ -1,11 +1,17 @@ <% content_for :extra_head_content do %> <%= machine_readable_metadata( - schema: :faq, + schema: :article, canonical_url: @content_item.canonical_url, body: @content_item.has_parts? ? @content_item.current_part_body : nil ) %> <% end %> +<% unless @content_item.requesting_a_part? %> + +<% end %> + <% content_for :simple_header, true %>