Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate FAQ schema from page body #1127

Merged
merged 1 commit into from
Sep 19, 2019
Merged

Generate FAQ schema from page body #1127

merged 1 commit into from
Sep 19, 2019

Conversation

sihugh
Copy link
Contributor

@sihugh sihugh commented Sep 19, 2019

What

At present, we're presenting a whole chapter of a guide in a single question/answer. This limits the impact of the content design we apply, because it doesn't break up the content in rich results in the same way as we do on GOV.UK.

We're also presenting all the chapters of the guide as structured data on the first chapter of the guide. This might run us foul of external search indexers because not all of the text is visible on the first page.

This PR moves to only generating structured markup for the chapter on which it's displayed. This allows us to split up the page into more bite-sized sections. We parse the govspeak generated HTML and uses the text in h2 headings as the "question", the id of the h2 to generate URLs with anchors, and the other markup as the "answer".

This enables us to display structured markup on on every chapter in a guide and also on other pages (such as mainstream answers). It also means that the Google results clash less with step by steps because it's more obvious that this is guidance, and not a "how to".

We will still avoid using this markup on travel advice pages because of the latency in results being updated.

I briefly disabled the Style/IfInsideElse cop because the alternatives seemed less appealing.

Example usage can be seen on the pages linked in alphagov/government-frontend#1492

Visual Changes

The rich Google result for default page in https://www.gov.uk/apply-to-come-to-the-uk:

Before (one rich result for a whole guide)

Screenshot 2019-09-19 09 39 46

After (one rich result per page in the guide)

Screenshot 2019-09-19 09 46 07

View Changes

https://govuk-publishing-compo-pr-1127.herokuapp.com/component-guide/machine_readable_metadata/a_guide

@bevanloon bevanloon temporarily deployed to govuk-publishing-compo-pr-1127 September 19, 2019 08:09 Inactive
@bevanloon bevanloon temporarily deployed to govuk-publishing-compo-pr-1127 September 19, 2019 08:12 Inactive
@bevanloon bevanloon temporarily deployed to govuk-publishing-compo-pr-1127 September 19, 2019 08:14 Inactive
@sihugh sihugh requested a review from bilbof September 19, 2019 08:48
@sihugh sihugh marked this pull request as ready for review September 19, 2019 08:48
@bevanloon bevanloon temporarily deployed to govuk-publishing-compo-pr-1127 September 19, 2019 08:50 Inactive
@bevanloon bevanloon temporarily deployed to govuk-publishing-compo-pr-1127 September 19, 2019 08:51 Inactive
@bevanloon bevanloon temporarily deployed to govuk-publishing-compo-pr-1127 September 19, 2019 08:52 Inactive
@bevanloon bevanloon temporarily deployed to govuk-publishing-compo-pr-1127 September 19, 2019 08:53 Inactive
Copy link
Contributor

@bilbof bilbof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. There's a minor issue with the html parsing method.

It might be worth us having guidance for content editors or devs on how to ensure FAQs get rendered in google results OK. So we would be consistent in our use of H2 (if we're not already), and know where to configure this.

At present, we're presenting a whole part of a guide as an FAQ question/answer.
This limits the impact of the content design we apply, because it doesn't
break up the content in rich results in the same way as we do on GOV.UK.

The code now parses the govspeak generated HTML and uses the text in h2
headings as the "question", the id of the h2 to generate URLs with anchors,
and the other markup as the "answer".

This enables us to display structured markup on more pages (such as mainstream
answers), and also on every part in a guide.

We will still avoid using this markup on travel advice pages because of the
latency in results being updated.

It now requires the body to be passed in directly to the machine readable
component rather than the component having to know too much about parts.

Disabling the Style/IfInsideElse rubocop because the alternatives are less
legible.
Copy link
Contributor

@bilbof bilbof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@sihugh sihugh merged commit c7e6dd0 into master Sep 19, 2019
@sihugh sihugh deleted the faq-iteration branch September 19, 2019 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants