diff --git a/app/components/ProductSpotlight.tsx b/app/components/ProductSpotlight.tsx index 676405b..d6fd9c8 100644 --- a/app/components/ProductSpotlight.tsx +++ b/app/components/ProductSpotlight.tsx @@ -1,3 +1,4 @@ +import { Fragment, type ReactNode } from "react"; import Image from "next/image"; import Link from "next/link"; import { AddToCartButton } from "./AddToCartButton"; @@ -7,6 +8,44 @@ import { getSpotlightProduct, getShippingSettings, getDefaultTaxRatePercent, get import { formatPrice, discountPercent } from "../lib/format"; import { effectiveTaxRate } from "../lib/cartTotals"; +type LexicalTextNode = { type: "text"; text: string; format?: number }; +type LexicalNode = { type: string; text?: string; format?: number; children?: LexicalNode[] }; + +// Minimal Lexical JSON → JSX converter for spotlightText — deliberately NOT +// the full block-oriented RichText.tsx (Posts/LegalPages' renderer, with +// its own heading/paragraph spacing and image/quote blocks). This teaser +// only ever needs paragraphs of plain text with optional bold spans +// (Lexical's text `format` bitmask: 1 = bold), rendered inline to match +// this section's own
treatment rather than
+// picking up article-level block styling.
+function renderInline(node: LexicalNode, key: number): ReactNode {
+ if (node.type === "text") {
+ const textNode = node as LexicalTextNode;
+ const bold = typeof textNode.format === "number" && (textNode.format & 1) === 1;
+ return bold ? {textNode.text} : {fallback}
+ {(paragraph.children ?? []).map((child, j) => renderInline(child, j))}
+
;
+ // Any other inline node (link, etc.) — render its text children without
+ // the wrapper itself; this teaser has no use for an actual here.
+ return (node.children ?? []).map((child, i) => renderInline(child, i));
+}
+
+function SpotlightText({ content, fallback }: { content: unknown; fallback: string }) {
+ const root = (content as { root?: { children?: LexicalNode[] } } | null)?.root;
+ if (!root?.children?.length) {
+ return
- {product.spotlightText || product.description} -
+