-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
6c9da0d
to
a8d7a65
Compare
a8d7a65
to
e1e78ba
Compare
e1e78ba
to
b76cf7b
Compare
b76cf7b
to
d32ff83
Compare
d32ff83
to
c01e6a1
Compare
c01e6a1
to
d08e1f1
Compare
lib/govuk_publishing_components/presenters/machine_readable/faq_page_schema.rb
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
d08e1f1
to
a3882d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
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)
After (one rich result per page in the guide)
View Changes
https://govuk-publishing-compo-pr-1127.herokuapp.com/component-guide/machine_readable_metadata/a_guide