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>
This commit is contained in:
2026-10-05 12:49:54 -04:00
co-authored by Claude Opus 5.5
parent 24eee8bc61
commit 9e05d16a46
11 changed files with 1093 additions and 1 deletions
+14 -1
View File
@@ -223,7 +223,20 @@ automatic** (D-021).
1 s apart, counted from requests actually sent (an abandoned wait holds no
slot); 2xx pages cached by URL for an hour (64 pages, oldest evicted), and
callers get their own copy of a cached body.
- Recipe data is parsed from schema.org `Recipe` JSON-LD.
- Recipe data is parsed from schema.org `Recipe` JSON-LD
(`recipes.Extract`): a small targeted scan of the page's
`application/ld+json` scripts and `og:site_name` (no HTML parser
dependency), finding the Recipe node at a script's top level, in a
top-level array or in an `@graph`, with `@type` a string or an array. The
largest image (by ImageObject width × height; the first of equals) is
resolved to an absolute URL; instructions — one string of lines, or a
list of strings, HowToSteps and HowToSections — are flattened in order;
ISO-8601 prep/cook/total times become minutes, total derived as prep +
cook when only those are given; the site name is the publisher's, else
`og:site_name`, else the host. A page with no Recipe is `ErrNoRecipe`,
with two is `ErrManyRecipes`; a shape schema.org does not allow — such as
a non-ISO-8601 duration like "20 minutes" — is `ErrMalformedRecipe`,
never guessed at.
- Photos are cached locally (`photos`) and processed with
`golang.org/x/image`.