schema.org Recipe JSON-LD extractor #66

2 Commits
Author SHA1 Message Date
dev_agentandClaude Opus 5.5 48338a0c3d Resolve JSON-LD @id references, accept schema.org type IRIs, refuse empty durations
CI / ci (push) Successful in 1m36s
CI / ci (pull_request) Successful in 1m36s
Review findings on the Recipe extractor:

- An image or publisher given as an {"@id": ...} reference now resolves to
  the node with that @id at a script's top level, in a top-level array or
  in an @graph, in any of the page's scripts. An image reference no node
  has, or one naming two nodes, is ErrMalformedRecipe; an unresolved
  publisher falls through to og:site_name and the host as before.
- @type matches the term or the absolute https:// or http://schema.org IRI,
  as a string or in an array, for Recipe, HowToStep and HowToSection.
- A present but empty or blank prepTime, cookTime or totalTime is an invalid
  ISO-8601 duration (ErrMalformedRecipe); an absent or null one is still
  nil.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 12:57:53 -04:00
dev_agentandClaude Opus 5.5 9e05d16a46 Add schema.org Recipe JSON-LD extractor
CI / ci (push) Successful in 1m35s
CI / ci (pull_request) Successful in 1m37s
recipes.Extract(page, url) scans a page's application/ld+json scripts and
og:site_name with a small targeted scanner (no new dependency) and returns
the single Recipe node: top level, top-level array or @graph, @type as a
string or array. It picks the largest image and resolves it against the
page URL, flattens HowToStep/HowToSection instructions in order, converts
ISO-8601 durations to minutes (total derived from prep + cook when absent),
and names the site from publisher, og:site_name or host. No Recipe is
ErrNoRecipe; two is ErrManyRecipes; shapes schema.org does not allow,
such as a "20 minutes" cookTime, are ErrMalformedRecipe.

testdata holds trimmed real pages from BBC Good Food, Budget Bytes,
RecipeTin Eats (HowToSection), King Arthur Baking, Delish (top-level
array), Food.com, Bon Appétit (non-ISO duration) and a Budget Bytes page
with no Recipe.

Maestro task 4c4570be-e0d2-43ad-90ea-0a4a9eeeb0b9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 12:49:54 -04:00