Landing page: use recipe images in cards, make cards clickable
Build and Deploy / build-and-deploy (push) Successful in 1m48s

- Card images now show the recipe's actual image when available
  (background-image: url(...) with background-size: contain to preserve
  aspect ratio without distortion), falling back to gradient placeholders
- Cards are now wrapped in <a href="/recipes/{filename}"> so clicking
  anywhere on a card navigates to the recipe page
- Added .contain CSS class for image-fit behavior and .lnd-card a for
  link styling
This commit is contained in:
2026-05-26 07:43:04 -04:00
parent 162d2f8a1e
commit 65b096bc31
+16 -2
View File
@@ -1334,7 +1334,9 @@ landingStyles =
, ""
, ".lnd-card { cursor: pointer; }"
, ".lnd-card-image { width: 100%; aspect-ratio: 1.3; border-radius: 8px; background-size: cover; background-position: center; background: linear-gradient(135deg, #E8B86A, #C9893F 60%, #8A5A2A); transition: opacity 0.15s; }"
, ".lnd-card-image.contain { background-size: contain; background-repeat: no-repeat; background-color: var(--roux-bg); }"
, ".lnd-card:hover .lnd-card-image { opacity: 0.92; }"
, ".lnd-card a { text-decoration: none; color: inherit; display: block; }"
, ".lnd-card-title { font-family: \"Fraunces\", serif; font-size: 17px; font-weight: 500; margin: 10px 0 4px; }"
, ".lnd-card-meta { font-size: 12px; color: #8A7560; }"
, ""
@@ -1439,18 +1441,30 @@ encodeRecipeJson recipes =
escapeChar '\t' = "\\t"
escapeChar c = T.singleton c
-- | Get the recipe image URL from RecipeInfo, if available.
getRecipeImage :: Idx.RecipeInfo -> Maybe Text
getRecipeImage info = case Idx.riRecipe info of
Right r -> metaImage (recipeMetadata r)
Left _ -> Nothing
-- | Render a landing page card for recently cooked (with date).
renderLandingCookedCard :: Text -> CookLog.CookEntry -> Idx.RecipeInfo -> Html
renderLandingCookedCard imgClass entry info =
H.a ! A.href (H.toValue ("/recipes/" <> T.pack (Idx.riFilename info))) $
H.div ! A.class_ "lnd-card" $ do
H.div ! A.class_ (H.toValue ("lnd-card-image " <> imgClass)) $ ""
case getRecipeImage info of
Just url -> H.div ! A.class_ "lnd-card-image contain" ! A.style (H.toValue ("background-image: url(" <> url <> ")")) $ ""
Nothing -> H.div ! A.class_ (H.toValue ("lnd-card-image " <> imgClass)) $ ""
H.div ! A.class_ "lnd-card-title" $ H.toHtml (Idx.riTitle info)
H.div ! A.class_ "lnd-card-meta" $ H.toHtml (formatDay (CookLog.ceCookedDate entry))
-- | Render a landing page card for recently added (with "Added" date).
renderLandingCard :: Text -> Idx.RecipeInfo -> Html
renderLandingCard imgClass info =
H.a ! A.href (H.toValue ("/recipes/" <> T.pack (Idx.riFilename info))) $
H.div ! A.class_ "lnd-card" $ do
H.div ! A.class_ (H.toValue ("lnd-card-image " <> imgClass)) $ ""
case getRecipeImage info of
Just url -> H.div ! A.class_ "lnd-card-image contain" ! A.style (H.toValue ("background-image: url(" <> url <> ")")) $ ""
Nothing -> H.div ! A.class_ (H.toValue ("lnd-card-image " <> imgClass)) $ ""
H.div ! A.class_ "lnd-card-title" $ H.toHtml (Idx.riTitle info)
H.div ! A.class_ "lnd-card-meta" $ H.toHtml ("Recently added" :: Text)