Repository navigation
feat(server): display custom list metadata (e.g. nutrition) on recipe pages - #458
Tloxipeuhca wants to merge 9 commits into
Conversation
… pages Any non-standard YAML frontmatter key whose value is a list (e.g. `nutrition:`) is now shown as its own line below the tags on the recipe and menu pages, one line per family. Nutrition entries get a matching icon (Tabler Icons, MIT) based on keyword: kcal/energy, protein, lipid/fat, sugar, fiber. The recipe list page shows a compact kcal badge next to tags when `nutrition:` is present. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…-hiding
Extends the custom metadata family display added in the previous commit:
- Supports a mapping form (`nutrition: {kcal: 234, proteins: 9.8, ...}`)
alongside the original list form, with per-field unit inference
(kcal -> kcal, everything else -> g) and 3 new nutrient fields
(saturated-fat, carbohydrates, salt) plus matching icons.
- Nutrient names and a new `file`/`meta` family (created-by/created-at/
modified-by/modified-at, with person/calendar/pencil/history icons) are
translated into the viewer's UI language via the existing Fluent i18n
system, across all 7 supported locales.
- A YAML key prefixed with "." is hidden from the recipe page, at either
the family level (`.file:`) or a single mapping entry (`.lipids:`).
- Refactors the per-family rendering into src/web/family_renderers/
(mod.rs + generic.rs + nutrition.rs + file.rs): a small FamilyRenderer
trait with a generic fallback, and an explicit renderer_for() registry
so adding a future specific renderer only touches one match arm.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
fabb100 to
eeca3ec
Compare
Update: mapping form, i18n, dot-hiding, generic fallbackFollowing review discussion, this PR now also supports: Mapping form + 3 new nutrition fields
nutrition:
kcal: 234
proteins: 9.8
lipids: 17.6
saturated-fat: 6.2
carbohydrates: 18.4
sugars: 8.9
fibers: 0.9
salt: 1.85The original list form ( New
|
Nutrition values apply to a single serving, which wasn't stated anywhere on the page. A hover-only tooltip was considered but rejected: the site is explicitly mobile-friendly, and tooltips don't work on touch. Instead, adds a small always-visible qualifier stacked under the "NUTRITION" label (translated across all 7 locales), via a new `note()` method on FamilyRenderer (default None, overridden by NutritionRenderer) so the mechanism stays available to any future family that needs one. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Closes #459 |
|
Thanks for that, will review in a day or two |
|
Hey @dubadub, just checking in on this when you have a chance. Thanks! |
1 similar comment
|
Hey @dubadub, just checking in on this when you have a chance. Thanks! |
|
Hi @Tloxipeuhca , sorry took me a while to get back to it. I like your idea of having separate rows per nested group. And also implementation is solid.. I'd fist pass some changes through the spec proposal (conventions file in a spec repo), so we can get the community feedback on these newly added conventions. This because people have diverse use-cases we might not think and instead of later making updates and migration scripts, I'd get feedback beforehand. For example, exact keys for nutrition metadata should be listed in conventions metadata section, so all apps on the same page. Also some choices should be considered: should it display per serving, per 100g or per recipe? Or support all of these? In some case I would expect it to scale with the recipe, that requires parser update. Also for prefixing with a dot, like the idea, but I'd first run it through proposal as well (probably easier than nutrition stuff). |
…ata-display Brings the branch from 0.34 up to upstream 0.41.1 and carries the nutrition and file panels over to the new design system. Conflicts resolved: docs/server.md (both sections kept), src/web/builders.rs, src/web/mod.rs and templates/recipes.html (upstream's recipe_card.html partial, with the kcal badge and the donut ported into it). Nutrition - One table of nutrients (crates/format/src/nutrition.rs) shared by the page, the cards and the JSON-LD output. The canonical keys are the schema.org NutritionInformation properties; kcal, lipids, proteins... stay accepted as aliases. salt is exported as sodiumContent; mono- and polyunsaturated fat and starch are shown but not exported. - Recipe page: a donut and the three macros for the servings chosen, small cards for the sub-nutrients coloured by how good they are for health per 100 g (green, amber, red, blue for no threshold) with a legend, a click on a slice of the donut that highlights what belongs to it, and the full table (per 100 g, per serving, whole recipe) behind a button that stays open across a change of servings. - Without a whole number of servings everything is per serving: no per-100 g column and no whole-recipe column. - Recipe list: the donut and the three macros on a card, the kcal badge otherwise. Metadata panels - One panel per family, built by that family's renderer and drawn by its own template under templates/panels/, in the order of the front matter, each in a frame titled on its border. - file: shows one chip per event (created, modified, translated from) and keeps a chip for any other key. A chip never grows wider than the screen, and a web link shows its host. - .metadata-pill wraps instead of overflowing on a phone. i18n: every label is translated in all ten locales. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… a change of servings Changing the servings reloads the page. The scroll position was only put back on the load event, so the page showed its top for a frame and then jumped to where the reader was. Restore it as soon as the content is parsed, and once more after the load, since images can change the height above the reader. Measured on a recipe with a photo and the nutrition table open: before, the timeline was [14 ms, scrollY 0] then [54 ms, scrollY 420]; after, the first frame is already at 420. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Lay out and rate the nutrition panel from per-standard YAML files (crates/format/data/standards): tree, reference intakes, rating thresholds, claims, cards and conventions. The standard is chosen in the preferences (cook_standard cookie, eu by default). - donut, macros with %, rated cards, always-visible legend, collapsible table with subtotals and % of reference intake, well-present tiles - explanation bubbles, multi-select, donut slice tooltip - list cards show macro percentages - translations in all 10 locales, docs and CLAUDE.md rule Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Dropdown above the table to switch between EU/US/UK and the flat "Essentials" table; the same choice is offered on /preferences (cook_standard=essential, cards still rated by eu) - Calmer, more readable table: neutral surface, quiet family headings, nutrient icons, minerals and vitamins folded by default, double-click to fold/unfold, tooltip only on the label - Sourced explanations (what / use / where / source) for 29 vitamins and minerals in every locale - Drop the tree-lines button and the standard/carbohydrate notes Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ines Recipe lists lost tags and nutrition when the front matter was longer than 30 lines. Use the branch behind cooklang/cooklang-find#42 until it is released; remove the patch then. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>



Closes #459
Summary
nutrition:) is now shown as its own line below the tags on the recipe and menu pages — one line per family, no code changes needed to support new families.nutrition:entries get a matching icon (Tabler Icons, MIT license, inlined as SVG — no new dependency) picked by keyword in the unit text: kcal/energy → flame, protein → meat, lipid/fat → droplet, sugar → candy, fiber → wheat. Unrecognized families/units render as a plain bullet.🔥 X kcalbadge next to the tags when a recipe hasnutrition:with a kcal entry.value%unit(e.g.258%kcal) and displayed as258 kcal.nutrition:also supports a mapping form (nutrition: {kcal: 234, proteins: 9.8, ...}) alongside the original list form, with per-field unit inference (kcal → kcal, everything else → g) and 3 additional nutrient fields (saturated-fat, carbohydrates, salt) with matching icons.filefamily (created-by/created-at/modified-by/modified-at) is now recognized, with person/calendar/pencil/history icons..is hidden from the recipe page, at either the family level (.file:) or a single mapping entry (.lipids:) — useful for metadata you want in the file but not shown to readers.src/web/family_renderers/(mod.rs+generic.rs+nutrition.rs+file.rs): a smallFamilyRenderertrait with a generic fallback, and an explicitrenderer_for()registry so adding a future specific renderer only touches one match arm.docs/server.md("Custom Metadata Families").Test plan
cargo build,cargo clippy --all-targets(clean, no warnings),cargo fmt --check— all pass.nutrition:forms, viacargo run -- server:file:/meta:metadata renders with the expected icons and translated labels..(family-level and entry-level) are correctly hidden.🤖 Generated with Claude Code