From 91b1f44ed1aa5706c437f11f1d2b27d0da98ef9c Mon Sep 17 00:00:00 2001 From: Simon Hughesdon Date: Mon, 9 Sep 2019 09:48:05 +0100 Subject: [PATCH] Resolve duplicate FAQ schemas We show the whole of a guide's FAQ schema on each of its chapters. I think this is OK, as long as the URLs that refer to the questions and answers are correct. (We might change this at some point though) The FAQ schema was appending the part slugs to the canonical URL of the page that it was displayed on. This works well for the default page in a guide, but less well for other chapters in the guide. The canonical URL is set (correctly) to [the URL of the chapter](https://tools.ietf.org/html/rfc6596). This means we were generating incorrect URLs. Correct example when viewing default page in a guide: When you view https://www.gov.uk/christmas-bonus you get links in the structured data like: - https://www.gov.uk/christmas-bonus/eligibility - https://www.gov.uk/christmas-bonus/how-to-claim Incorrect example when viewing sub chapter in a guide: When you view https://www.gov.uk/christmas-bonus/eligibility you get links in the structured data like: - https://www.gov.uk/christmas-bonus/eligibility/eligibility - https://www.gov.uk/christmas-bonus/eligibility/how-to-claim This fix should get us links like: - https://www.gov.uk/christmas-bonus/eligibility - https://www.gov.uk/christmas-bonus/how-to-claim --- .../presenters/machine_readable/faq_page_schema.rb | 8 ++++++-- .../presenters/schema_org_spec.rb | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/govuk_publishing_components/presenters/machine_readable/faq_page_schema.rb b/lib/govuk_publishing_components/presenters/machine_readable/faq_page_schema.rb index 9cc4e52e66..9cfee9674d 100644 --- a/lib/govuk_publishing_components/presenters/machine_readable/faq_page_schema.rb +++ b/lib/govuk_publishing_components/presenters/machine_readable/faq_page_schema.rb @@ -42,11 +42,15 @@ def questions_and_answers def part_url(part, index) if index.zero? - page.canonical_url + guide_url else - page.canonical_url + "/" + part["slug"] + guide_url + "/" + part["slug"] end end + + def guide_url + Plek.new.website_root + page.base_path + end end end end diff --git a/spec/lib/govuk_publishing_components/presenters/schema_org_spec.rb b/spec/lib/govuk_publishing_components/presenters/schema_org_spec.rb index 1f7829d76d..34cc506335 100644 --- a/spec/lib/govuk_publishing_components/presenters/schema_org_spec.rb +++ b/spec/lib/govuk_publishing_components/presenters/schema_org_spec.rb @@ -63,7 +63,10 @@ end it "generates schema.org FAQPages" do - content_item = GovukSchemas::RandomExample.for_schema(frontend_schema: "guide") do |random_item| + content_item = GovukSchemas::RandomExample.for_schema( + frontend_schema: "guide", + canonical_url: "http://www.dev.gov.uk/how-to-train-your-dragon/insurance" + ) do |random_item| random_item.merge( "base_path" => "/how-to-train-your-dragon", "details" => {