Skip to content

Commit

Permalink
Resolve duplicate FAQ schemas
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sihugh committed Sep 9, 2019
1 parent a4c7972 commit 91b1f44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down

0 comments on commit 91b1f44

Please sign in to comment.