frontend icon indicating copy to clipboard operation
frontend copied to clipboard

[WIP] Linked data for recipes

Open cemms1 opened this issue 1 year ago • 1 comments

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 the article.content.schemaOrg.recipe from CAPI and convert into a LinkedData 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:

cemms1 avatar Feb 27 '24 15:02 cemms1

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 in LinkedData for the recipe case in the forArticle 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.

cemms1 avatar Mar 01 '24 14:03 cemms1

Where we've got to:

  • We can recognise when an article has a Some schemaOrg.recipe field
  • We need to convert every _atType and every atContext within the SchemaRecipe 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, having frontend as the only real "client" of this

cemms1 avatar Mar 07 '24 17:03 cemms1

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

image

frederickobrien avatar Mar 15 '24 15:03 frederickobrien

Seen on ADMIN-PROD (merged by @cemms1 12 minutes and 13 seconds ago)

prout-bot avatar Mar 18 '24 11:03 prout-bot

Seen on FRONTS-PROD (merged by @cemms1 14 minutes and 23 seconds ago)

prout-bot avatar Mar 18 '24 11:03 prout-bot

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"):

image

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

image

rtyley avatar Mar 20 '24 11:03 rtyley