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 |



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