Repository navigation
feat(server): nutrition dashboard with EU, US and UK standards and explained nutrients - #857
Open
Tloxipeuhca wants to merge 13 commits into
Open
Tloxipeuhca wants to merge 13 commits into
Tloxipeuhca wants to merge 13 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 <[email protected]>
…-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 <[email protected]>
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 <[email protected]>
…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 <[email protected]>
… 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 <[email protected]>
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 <[email protected]>
- 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 <[email protected]>
…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 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
- A value written with a unit (`20 g`, `0.4 g`, `1255 kJ`) is converted to the unit of its key before it is computed, shown or exported. Bare numbers are unchanged. Before, such values showed a doubled unit, dropped the table and left the JSON-LD without nutrition. - Decimals of the nutrition panel and cards use a comma where the language does. - A nutrient outside a standard's table is named like the other rows. - Docs: units, carbohydrates including fibre, and two stale mentions. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The release holds the fix for front matter over 30 lines, so the temporary patch pointing at a fork goes. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…play Conflicts were additions on both sides, all kept: the cooking-mode notes next to the nutrition documentation and messages, and the source link metadata next to the family panels in src/web/builders.rs. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The figure shown is the total sugars, while the explanation defined the free sugars. It now gives the definition of Annex I of Regulation (EU) 1169/2011, then says which sugars the WHO limits. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #459
Replaces #458
Context: a nutrition dashboard for every recipe
CookCLI helps to choose, scale, shop for and cook a recipe, but its web interface does not say what ends up on the plate. This PR adds a nutrition dashboard: from the figures written in the recipe, it takes the cook from a glance to the detail, one question at a time.
A list of numbers would not do this. "Vitamin K 420 µg" or "saturated fat 11 g" raises questions: what is it, is that a lot, and according to whom? The answers differ from one country to the next. So before building the display, I worked out how a nutrition label is read under three norms, which of those rules come from a published text, and what a reader needs in order to understand them.
1. Analysis: one recipe, three ways to read it
A single hard-coded table would therefore be wrong for most readers.
Sources, and how far each was verified
The EU texts were read on the UK-retained copies on legislation.gov.uk, which keep the EU wording.
Each of these statuses is written in the standard's own data file, next to its source. A value that could not be confirmed is flagged there and listed above.
2. Helping the reader understand each nutrient
Hovering, focusing or tapping a nutrient (card or table row) opens an explanation bubble. It answers, in order:
Pointing at a card of the summary: saturated fat
Pointing at a row of the table: vitamin D
The rating explained under the UK norm: sugars
The same bubble follows the US norm: sodium
Pointing at a slice of the donut
No sourced text yet: the bubble says so
Editorial rules I followed:
3. From the analysis to the design
crates/format/data/standards/). The code lays out what the file says. Adding a norm means adding a file, registering it and naming it in each language.weight:for per 100 g), the card stays unrated.Where to look in the code
crates/format/data/standards/crates/format/src/reference.rscrates/format/src/nutrition.rssrc/web/family_renderers/panel.rstemplates/panels/nutrition.htmldocs/server.md4. What the reader gets
Summary, European Union
Traffic lights, United Kingdom
Full table with the "well present" vitamins and minerals
On a phone
Values in the screenshots are illustrative.
NutritionInformationin the JSON-LD export.More screenshots: US and UK norms, Essentials view, highlighting, recipe list, phone table, French
Summary, United States
Full table, United States
Summary, United Kingdom
Essentials view
One macro highlighted
Recipe list cards
Table on a phone, one column at a time
In French, with decimal commas
An explanation in French
Also in this PR
file:/meta:shows created, modified and translated-from..is hidden from the page.5. Choices on the format
nutrition:mapping; thevalue%unitlist is still readNutritionInformationnames (fatContent,proteinContent...), plussalt, minerals and vitamins; short spellings (fat,protein...) are accepted as aliases20 g,0.4 g,1255 kJ) is converted before any calculationservings; without a whole number of servings, everything stays per servingweight:, the weight of the whole recipecrates/format/src/nutrition.rs) for the page, the cards and the exportThe reference form: schema.org names, bare numbers
Also accepted: short spellings and written units, as an importer may write them
Test plan
cargo fmt --all --checkandcargo clippy --workspace --all-targets -- -D warnings: clean.cargo test --workspace: 2023 tests pass. Two pantry permission tests fail when cargo runs as root, and pass as a normal user.cookbinary, which that setup did not have;🤖 Generated with Claude Code