From fee43349f9868f8797f280cf180a22a3999cc236 Mon Sep 17 00:00:00 2001 From: William Grant Date: Wed, 15 Sep 2021 09:38:14 +1000 Subject: [PATCH] updated contentful deps, improved image rendering for rich content --- components/RichBody.tsx | 37 +++++++++++++++++++++++++++---------- package.json | 8 ++++---- services/render.tsx | 19 ++++++++++--------- yarn.lock | 38 +++++++++++++++++++------------------- 4 files changed, 60 insertions(+), 42 deletions(-) diff --git a/components/RichBody.tsx b/components/RichBody.tsx index 6913910..8bb65c0 100644 --- a/components/RichBody.tsx +++ b/components/RichBody.tsx @@ -76,16 +76,33 @@ export function RichBody(props: Props): ReactElement { // const children; const plaintext = documentToPlainTextString(node); const isShortcode = CMS.SHORTCODE_REGEX.test(plaintext); - - return isShortcode ? ( - renderShortcode(plaintext) - ) : ( -

- {children} -

- ); + if (isShortcode) { + return renderShortcode(plaintext); + } else { + let hasImage = false; + Children.map(children, (child: any) => { + if (child.type === 'figure') { + hasImage = true; + return; + } + }); + if (hasImage) { + return ( + + {children} + + ); + } + return ( +

+ {children} +

+ ); + } }, [BLOCKS.HEADING_1]: (node, children) => (

+