Skip to content

Commit

Permalink
Render HTML on ProductDetails (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpprieto committed Jun 23, 2022
1 parent 761d7a8 commit 0e798d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export function ProductDetail({
</Disclosure.Button>

<Disclosure.Panel className={'pb-4 pt-2 grid gap-2'}>
<Text as="div">{content}</Text>
<div
className="prose dark:prose-invert"
dangerouslySetInnerHTML={{__html: content}}
/>
{learnMore && (
<div className="">
<Link
Expand Down
4 changes: 2 additions & 2 deletions templates/demo-store/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export function isDiscounted(price: MoneyV2, compareAtPrice: MoneyV2) {

export function getExcerpt(text: string) {
const regex = /<p.*>(.*?)<\/p>/;
const correspondingText = regex.exec(text);
return correspondingText ? correspondingText[1] : '';
const match = regex.exec(text);
return match?.length ? match[0] : text;
}

function resolveToFromType(
Expand Down
8 changes: 4 additions & 4 deletions templates/demo-store/src/routes/products/[handle].server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function Product() {
},
});

const {media, title, vendor, description, id} = product;
const {media, title, vendor, descriptionHtml, id} = product;
const {shippingPolicy, refundPolicy} = shop;

return (
Expand All @@ -79,10 +79,10 @@ export default function Product() {
</div>
<ProductForm />
<div className="grid gap-4 py-4">
{description && (
{descriptionHtml && (
<ProductDetail
title="Product Details"
content={description}
content={descriptionHtml}
/>
)}
{shippingPolicy?.body && (
Expand Down Expand Up @@ -123,7 +123,7 @@ const PRODUCT_QUERY = gql`
id
title
vendor
description
descriptionHtml
media(first: 7) {
nodes {
...Media
Expand Down

0 comments on commit 0e798d6

Please sign in to comment.