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 11, 2024
1 parent 18eef34 commit 19c0f47
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 19c0f47

Please sign in to comment.