From 0bbd6db36f94ed3fa6356eacc540884b78914f03 Mon Sep 17 00:00:00 2001 From: Summer Cook Date: Fri, 2 Feb 2024 12:44:18 -0800 Subject: [PATCH 1/2] get markdown working on browse pages, homepage should still use snippet --- src/compounds/Item/CardBody.jsx | 45 +++++++++++++---------------- src/compounds/Item/Item.jsx | 6 +++- src/compounds/Item/Item.stories.jsx | 2 ++ 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/compounds/Item/CardBody.jsx b/src/compounds/Item/CardBody.jsx index e02c93d1..9c1deb27 100644 --- a/src/compounds/Item/CardBody.jsx +++ b/src/compounds/Item/CardBody.jsx @@ -4,19 +4,10 @@ import { Button, Card, Collapse } from 'react-bootstrap' import NextLink from '../../components/NextLink/NextLink' import LinkedButton from '../LinkedButton/LinkedButton' -const CardBody = ({ buttonLink, buttonProps, item, - orientation, titleLink, withButtonLink, withTitleLink }) => { - const { id, description = '', name } = item +const CardBody = ({ buttonLink, buttonProps, item, markdownDescriptionTruncated, markdownDescriptionExtended, orientation, titleLink, withButtonLink, withTitleLink }) => { + const { id, description, name, snippet } = item const [open, setOpen] = useState(false) - const truncateDescription = (desc, maxLength, isOpen) => { - if (desc.length <= maxLength || isOpen) return { truncated: desc, cutOffIndex: desc.length }; - const lastSpaceIndex = desc.substring(0, maxLength).lastIndexOf(' '); - const ellipsis = isOpen ? '' : '...'; - return { truncated: desc.slice(0, lastSpaceIndex) + ellipsis, cutOffIndex: lastSpaceIndex }; - } - - const { truncated, cutOffIndex } = truncateDescription(description, 300, open) return (
@@ -33,21 +24,25 @@ const CardBody = ({ buttonLink, buttonProps, item, name )} - {description && ( - <> -
- {truncated} - -
{description.slice(cutOffIndex).trimStart()}
-
-
- {description.length > 300 && ( - + {orientation === 'horizontal' ? ( + <> +
+ {markdownDescriptionTruncated} + +
{markdownDescriptionExtended}
+
+
+ {description?.length > 300 && ( + + )} + + ) : ( +
+ {snippet} +
)} - - )}
{(withButtonLink) && (
diff --git a/src/compounds/Item/Item.jsx b/src/compounds/Item/Item.jsx index 035096ca..65ee1658 100644 --- a/src/compounds/Item/Item.jsx +++ b/src/compounds/Item/Item.jsx @@ -8,7 +8,7 @@ import ItemLoading from './ItemLoading' import NextLink from '../../components/NextLink/NextLink' import './item.scss' -const Item = ({ buttonLink, buttonProps, href, isLoading, item, orientation, titleLink, withButtonLink, +const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownDescriptionExtended, href, isLoading, item, orientation, titleLink, withButtonLink, withTitleLink, width }) => { if (isLoading) { return ( @@ -45,6 +45,8 @@ const Item = ({ buttonLink, buttonProps, href, isLoading, item, orientation, tit buttonLink={link} buttonProps={buttonProps} item={item} + markdownDescriptionTruncated={markdownDescriptionTruncated} + markdownDescriptionExtended={markdownDescriptionExtended} orientation={orientation} titleLink={link} withButtonLink={withButtonLink} @@ -65,6 +67,8 @@ const Item = ({ buttonLink, buttonProps, href, isLoading, item, orientation, tit buttonLink={link} buttonProps={buttonProps} item={item} + markdownDescriptionTruncated={markdownDescriptionTruncated} + markdownDescriptionExtended={markdownDescriptionExtended} orientation={orientation} titleLink={link} withButtonLink={withButtonLink} diff --git a/src/compounds/Item/Item.stories.jsx b/src/compounds/Item/Item.stories.jsx index 90d69107..53cb3a91 100644 --- a/src/compounds/Item/Item.stories.jsx +++ b/src/compounds/Item/Item.stories.jsx @@ -31,6 +31,8 @@ Default.args = { style: {}, withButtonLink: false, withTitleLink: false, + markdownDescriptionTruncated: 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', + markdownDescriptionExtended: ' Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.' } export const isLoading = Template.bind({}) From f2c93207904615146725549ea65bd0526d4e6ac2 Mon Sep 17 00:00:00 2001 From: Summer Cook Date: Fri, 2 Feb 2024 13:30:49 -0800 Subject: [PATCH 2/2] add proptypes for markdown props --- src/compounds/Item/CardBody.jsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compounds/Item/CardBody.jsx b/src/compounds/Item/CardBody.jsx index 9c1deb27..68152615 100644 --- a/src/compounds/Item/CardBody.jsx +++ b/src/compounds/Item/CardBody.jsx @@ -78,6 +78,14 @@ CardBody.propTypes = { name: PropTypes.string.isRequired, slug: PropTypes.string, }), + markdownDescriptionTruncated: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.elementType, + ]), + markdownDescriptionExtended: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.elementType, + ]), orientation: PropTypes.oneOf(['horizontal', 'vertical']), titleLink: PropTypes.string, withButtonLink: PropTypes.bool, @@ -90,6 +98,8 @@ CardBody.defaultProps = { item: { description: '', }, + markdownDescriptionTruncated: '', + markdownDescriptionExtended: '', orientation: 'vertical', titleLink: '', withButtonLink: false,