feat(server): display custom list metadata (e.g. nutrition) on recipe pages - #458
feat(server): display custom list metadata (e.g. nutrition) on recipe pages#458Tloxipeuhca wants to merge 3 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). |



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