Skip to content

Commit

Permalink
lazy load large blog images
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Sep 6, 2024
1 parent 41da4cb commit bce80b9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/lib-content/src/components/Article/Article.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Anchor, Box, Heading, Paragraph, ResponsiveContext } from 'grommet'
import { Anchor, Box, Heading, Image, Paragraph, ResponsiveContext } from 'grommet'
import { string } from 'prop-types'
import { useTranslation } from '../../translations/i18n.js'
import styled from 'styled-components'
Expand All @@ -9,6 +9,10 @@ const StyledParagraph = styled(Paragraph)`
line-height: 1.2;
`

const thumbnailSize = {
max: '120px',
min: '120px'
}
export default function Article({
date = '',
excerpt = '',
Expand All @@ -33,11 +37,17 @@ export default function Article({
{imageSrc.length && size !== 'small' ? (
<Box
alignSelf='center'
background={`url('${imageSrc}')`}
flex='grow'
height={{ max: '120px', min: '120px' }}
width={{ max: '120px', min: '120px' }}
/>
height={thumbnailSize}
width={thumbnailSize}
>
<Image
fit='cover'
src={imageSrc}
alt={title}
loading='lazy'
/>
</Box>
) : null}
<Box>
<SpacedText
Expand Down

0 comments on commit bce80b9

Please sign in to comment.