frontend
frontend copied to clipboard
[WIP] Linked data for recipes
Recipe structured data
Part of https://github.com/guardian/dotcom-rendering/issues/10532
- We are retrieving structured schema org data from CAPI, so ideally do not want to parse or validate this again as we expect it to come in a certain format from the CAPI client.
- We need to send
List[LinkedData]
to DCR, so need to receive thearticle.content.schemaOrg.recipe
from CAPI and convert into aLinkedData
object - As part of the above, we will need to convert the
_at
part of the fields to@
since these do not come through as expected from the API models. - There are no unit tests for the
LinkedData
package as far as I can see so we need to create a test for this serialization process to verify that it works as expected
For local development and testing:
- It would be great to have a snapshot/prepublished version of the CAPI data models and the CAPI scala client
Update of things still outstanding:
- Update the CAPI models and CAPI scala client snapshot versions to include the recent work on sponsored packages
- Run
dev-build
locally, ensuring the.gu/frontend.conf
file has entries for CAPI CODE environment (content.api.host
,content.api.key
) a - If testing using debug mode, make sure to set the
--debug
flag when running the./sbt
command and set breakpoints inLinkedData
for therecipe
case in theforArticle
method. - Try to access the CODE article http://localhost:9000/food/2024/feb/03/yotam-ottolenghi-alternative-pancake-day-recipes-rice-egg-harissa-cheese-crempogau (there's a basic test article without recipe schema here if needed
Ideally we'd also get a test file working to check the logic for returning recipe schema org data.
A possible improvement at this point might be to decode and encode the JSON object from schemaOrg.recipe
rather than to stringify it and parse again.
Where we've got to:
- We can recognise when an article has a
Some
schemaOrg.recipe
field - We need to convert every
_atType
and everyatContext
within theSchemaRecipe
data structure to@type
and@context
because of a limitation with thrift not allowing the@
symbol.- One way of doing this might be to use Play Json but in order to do this we will need to fully define our output type (?) in order to define the Json.reads and Json.writes functions. This is not ideal due to wanting to pass the entire model response straight through, only changing these two fields throughout the object.
- It would be useful to understand if this is possible from any Scala experts before we take too much time trying various methods in order to achieve this
- If it will take too much effort/time or require a high level of schema definition within the
frontend
repo it would be worth evaluating whether CAPI is really the right place for this data, havingfrontend
as the only real "client" of this
Testing this in CODE and it's looking really good, valid schema coming through for a selection of single and multi-recipe articles:
- https://m.code.dev-theguardian.com/food/2021/sep/29/how-to-make-tiramisu-recipe-masterclass-felicity-cloake
- https://m.code.dev-theguardian.com/food/2024/mar/09/vegan-peanut-butter-ramen-recipe-meera-sodha
- https://m.code.dev-theguardian.com/food/2024/jan/27/30-minute-meal-yotam-ottolenghi-recipes-thai-deep-fried-omelette-tofu-broccoli-spicy-seaweed-sea-bass-spaghetti
Using https://validator.schema.org/ to confirm the ld+json
blob is valid. No errors or warnings found as yet
Seen on ADMIN-PROD (merged by @cemms1 12 minutes and 13 seconds ago)
- Check your changes on www.theguardian.com ✔️
- Keep an eye on the deploy dashboard 📉
Seen on FRONTS-PROD (merged by @cemms1 14 minutes and 23 seconds ago)
- Check your changes on www.theguardian.com ✔️
- Keep an eye on the deploy dashboard 📉
I'm not sure if this is important, but I wanted to share that I received this warning this morning from Google Search Console ("New Recipes structured data issues detected"):
Top critical issues* : Missing field 'name'
It looks like this is actually only on one url:
https://www.theguardian.com/food/2021/mar/21/joe-trivelli-recipes-asparagus-and-potato-schiacciata-cherry-ice-cream-sandwiches