diff --git a/frontend/app/components/Domain/Recipe/RecipeNutrition.vue b/frontend/app/components/Domain/Recipe/RecipeNutrition.vue
index 30a4f86d4..bebd25346 100644
--- a/frontend/app/components/Domain/Recipe/RecipeNutrition.vue
+++ b/frontend/app/components/Domain/Recipe/RecipeNutrition.vue
@@ -7,6 +7,25 @@
{{ $t("recipe.per-serving") }}
+
+
+
+
+ {{ total.label }}
+ {{ total.value }}
+ {{ total.suffix }}
+
+
+
-
+
-
-
- {{ item.label }}
-
- {{ item.value }}
+
+ {{ item.label }}
+
+
+
{{ item.value }}
+
+ {{ item.suffix }}
-
{{ item.suffix }}
-
-
-
+
+
+
+
(null);
+/** Abbreviated units. Mealie's own suffixes are spelled out ("milligrams"),
+ * which is wider than the value column in the recipe page's narrow aside.
+ * Scoped to this card rather than changing the shared i18n strings. */
+const MILLIGRAM_FIELDS = new Set(["cholesterolContent", "sodiumContent"]);
+
+function unitFor(key: number | string): string {
+ if (key === "calories") {
+ return i18n.t("recipe.nutrition-unit-calories");
+ }
+ return MILLIGRAM_FIELDS.has(String(key))
+ ? i18n.t("recipe.nutrition-unit-milligrams")
+ : i18n.t("recipe.nutrition-unit-grams");
+}
+
+/** The five figures people actually look for first. */
+const HEADLINE_KEYS: { key: keyof Nutrition; labelKey: string }[] = [
+ { key: "calories", labelKey: "recipe.nutrition-abbr-calories" },
+ { key: "fatContent", labelKey: "recipe.nutrition-abbr-fat" },
+ { key: "proteinContent", labelKey: "recipe.nutrition-abbr-protein" },
+ { key: "carbohydrateContent", labelKey: "recipe.nutrition-abbr-carbs" },
+ { key: "fiberContent", labelKey: "recipe.nutrition-abbr-fiber" },
+];
+
const valueNotNull = computed(() => {
let key: keyof Nutrition;
for (key in modelValue.value) {
@@ -117,6 +165,17 @@ const valueNotNull = computed(() => {
const showViewer = computed(() => !props.edit && valueNotNull.value);
+const headlineTotals = computed(() =>
+ HEADLINE_KEYS
+ .filter(({ key }) => modelValue.value[key]?.trim())
+ .map(({ key, labelKey }) => ({
+ key,
+ label: i18n.t(labelKey),
+ value: modelValue.value[key] as string,
+ suffix: unitFor(key),
+ })),
+);
+
// The calculator works on the rendered ingredient text, which is what the
// backend's parser expects as input.
const ingredientLines = computed(() =>
@@ -158,6 +217,7 @@ const renderedList = computed(() => {
if (modelValue.value[key]?.trim()) {
item[key] = {
...label,
+ suffix: unitFor(key),
value: modelValue.value[key],
};
}
diff --git a/frontend/app/lang/messages/en-US.json b/frontend/app/lang/messages/en-US.json
index d92174376..1eb0ea857 100644
--- a/frontend/app/lang/messages/en-US.json
+++ b/frontend/app/lang/messages/en-US.json
@@ -744,7 +744,15 @@
"nutrition-lookup-failed": "Could not reach the nutrition service.",
"nutrition-no-match": "No match found - this ingredient will be skipped.",
"nutrition-not-configured": "Nutrition lookup is not configured on this server.",
- "nutrition-skipped": "skipped"
+ "nutrition-skipped": "skipped",
+ "nutrition-abbr-calories": "Cal",
+ "nutrition-abbr-carbs": "Carbs",
+ "nutrition-abbr-fat": "Fat",
+ "nutrition-abbr-fiber": "Fiber",
+ "nutrition-abbr-protein": "Protein",
+ "nutrition-unit-calories": "kcal",
+ "nutrition-unit-grams": "g",
+ "nutrition-unit-milligrams": "mg"
},
"recipe-finder": {
"recipe-finder": "Recipe Finder",