Skip to content

Commit 0bbd6db

Browse files
committed
get markdown working on browse pages, homepage should still use snippet
1 parent d3ae323 commit 0bbd6db

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

src/compounds/Item/CardBody.jsx

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,10 @@ import { Button, Card, Collapse } from 'react-bootstrap'
44
import NextLink from '../../components/NextLink/NextLink'
55
import LinkedButton from '../LinkedButton/LinkedButton'
66

7-
const CardBody = ({ buttonLink, buttonProps, item,
8-
orientation, titleLink, withButtonLink, withTitleLink }) => {
9-
const { id, description = '', name } = item
7+
const CardBody = ({ buttonLink, buttonProps, item, markdownDescriptionTruncated, markdownDescriptionExtended, orientation, titleLink, withButtonLink, withTitleLink }) => {
8+
const { id, description, name, snippet } = item
109
const [open, setOpen] = useState(false)
1110

12-
const truncateDescription = (desc, maxLength, isOpen) => {
13-
if (desc.length <= maxLength || isOpen) return { truncated: desc, cutOffIndex: desc.length };
14-
const lastSpaceIndex = desc.substring(0, maxLength).lastIndexOf(' ');
15-
const ellipsis = isOpen ? '' : '...';
16-
return { truncated: desc.slice(0, lastSpaceIndex) + ellipsis, cutOffIndex: lastSpaceIndex };
17-
}
18-
19-
const { truncated, cutOffIndex } = truncateDescription(description, 300, open)
2011
return (
2112
<Card.Body className={withButtonLink && 'd-flex flex-column'}>
2213
<div className={orientation === 'horizontal' ? 'd-block d-md-flex align-items-center justify-content-between' : ''}>
@@ -33,21 +24,25 @@ const CardBody = ({ buttonLink, buttonProps, item,
3324
name
3425
)}
3526
</Card.Title>
36-
{description && (
37-
<>
38-
<div className='fw-light mh-300 overflow-auto mt-3'>
39-
{truncated}
40-
<Collapse in={open}>
41-
<div className='fw-light'>{description.slice(cutOffIndex).trimStart()}</div>
42-
</Collapse>
43-
</div>
44-
{description.length > 300 && (
45-
<Button variant="link" onClick={() => setOpen(!open)} className="p-0 mt-3">
46-
{open ? ' Show less' : ' Read more'}
47-
</Button>
27+
{orientation === 'horizontal' ? (
28+
<>
29+
<div className='fw-light mh-300 overflow-auto mt-3'>
30+
{markdownDescriptionTruncated}
31+
<Collapse in={open}>
32+
<div className='fw-light'>{markdownDescriptionExtended}</div>
33+
</Collapse>
34+
</div>
35+
{description?.length > 300 && (
36+
<Button variant="link" onClick={() => setOpen(!open)} className="p-0 mt-3">
37+
{open ? ' Show less' : ' Read more'}
38+
</Button>
39+
)}
40+
</>
41+
) : (
42+
<div className='fw-light'>
43+
{snippet}
44+
</div>
4845
)}
49-
</>
50-
)}
5146
</div>
5247
{(withButtonLink) && (
5348
<div className={orientation === 'horizontal' ? 'mt-3 mt-md-0' : 'mt-3'}>

src/compounds/Item/Item.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ItemLoading from './ItemLoading'
88
import NextLink from '../../components/NextLink/NextLink'
99
import './item.scss'
1010

11-
const Item = ({ buttonLink, buttonProps, href, isLoading, item, orientation, titleLink, withButtonLink,
11+
const Item = ({ buttonLink, buttonProps, markdownDescriptionTruncated, markdownDescriptionExtended, href, isLoading, item, orientation, titleLink, withButtonLink,
1212
withTitleLink, width }) => {
1313
if (isLoading) {
1414
return (
@@ -45,6 +45,8 @@ const Item = ({ buttonLink, buttonProps, href, isLoading, item, orientation, tit
4545
buttonLink={link}
4646
buttonProps={buttonProps}
4747
item={item}
48+
markdownDescriptionTruncated={markdownDescriptionTruncated}
49+
markdownDescriptionExtended={markdownDescriptionExtended}
4850
orientation={orientation}
4951
titleLink={link}
5052
withButtonLink={withButtonLink}
@@ -65,6 +67,8 @@ const Item = ({ buttonLink, buttonProps, href, isLoading, item, orientation, tit
6567
buttonLink={link}
6668
buttonProps={buttonProps}
6769
item={item}
70+
markdownDescriptionTruncated={markdownDescriptionTruncated}
71+
markdownDescriptionExtended={markdownDescriptionExtended}
6872
orientation={orientation}
6973
titleLink={link}
7074
withButtonLink={withButtonLink}

src/compounds/Item/Item.stories.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Default.args = {
3131
style: {},
3232
withButtonLink: false,
3333
withTitleLink: false,
34+
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.',
35+
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.'
3436
}
3537

3638
export const isLoading = Template.bind({})

0 commit comments

Comments
 (0)