Problem/Motivation
When I use an FAQ block in layout builder I would like it to automatically add structured data to the page.
Proposed resolution
In the rocketship_blocks.module we can attach the json ld information to the head of the site for each block it finds on the page.
Similarly to how easy breadcrumb module does it: https://git.drupalcode.org/issue/easy_breadcrumb-3292422/-/blob/3292422-...
The structure of the json would be as follows:
This is an example FAQ title
This is the resulting FAQ answer. Which will also be added in the structured data of this page so Google can process it accordingly.
This is a second FAQ item
This is the answer to the second item.
Structured data to be added in the source code for above example:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [{
"@type": "Question",
"name": "This is an example FAQ title",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the resulting FAQ answer. Which will also be added in the structured data of this page so Google can process it accordingly."
}
},{
"@type": "Question",
"name": "This is a second FAQ item",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the answer to the second item."
}
}]
}
</script>
For each FAQ block on the page it should have another script tag of structured data.
Comment | File | Size | Author |
---|---|---|---|
#4 | interdiff_2_4.txt | 3.48 KB | nginex |
#4 | rocketship_core-3292460-4.patch | 5.55 KB | nginex |
Comments
Comment #2
HitchShockImplemented SOE solution for FAQ block.
Comment #3
sdstyles CreditAttribution: sdstyles as a volunteer and at Dropsolid commentedThe patch works as expected, the FAQ data is injected into the page.
Comment #4
nginex CreditAttribution: nginex as a volunteer and at Dropsolid for Dropsolid commentedCode cleaning and refactoring.
Comment #6
nginex CreditAttribution: nginex as a volunteer and at Dropsolid for Dropsolid commented