Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit be0fec2

Browse files
committed
use QueryImage for articles related image
1 parent 1938600 commit be0fec2

File tree

2 files changed

+50
-35
lines changed

2 files changed

+50
-35
lines changed

src/pages/blog/components/_banner.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react'
22
import styled from 'styled-components'
33
import PropTypes from 'prop-types'
4+
import { getImage } from 'gatsby-plugin-image'
5+
import { QueryImage } from 'components/elements'
46
import { Flex } from 'components/containers'
57
import { LocalizedLink } from 'components/localization'
68
import device from 'themes/device'
@@ -13,9 +15,6 @@ const ParentWrapper = styled(Flex)`
1315
max-width: ${(props) => (props.max_w_tablet ? props.max_w_tablet : '100%')};
1416
}
1517
`
16-
const ImgWrapper = styled.img`
17-
width: 100%;
18-
`
1918
const DesktopWrapper = styled(Flex)`
2019
@media ${device.tabletS} {
2120
display: none;
@@ -40,16 +39,16 @@ const Banner = ({ detailsObj }) => {
4039
>
4140
{detailsObj.imgSrcDesktop && !detailsObj.imgSrcMobile && (
4241
<>
43-
<ImgWrapper src={detailsObj.imgSrcDesktop} />
42+
<QueryImage data={getImage(detailsObj.imgSrcDesktop)} alt="" />
4443
</>
4544
)}
4645
{detailsObj.imgSrcDesktop && detailsObj.imgSrcMobile && (
4746
<>
4847
<DesktopWrapper>
49-
<ImgWrapper src={detailsObj.imgSrcDesktop} />
48+
<QueryImage data={getImage(detailsObj.imgSrcDesktop)} alt="" />
5049
</DesktopWrapper>
5150
<MobileWrapper>
52-
<ImgWrapper src={detailsObj.imgSrcMobile} />
51+
<QueryImage data={getImage(detailsObj.imgSrcMobile)} alt="" />
5352
</MobileWrapper>
5453
</>
5554
)}
@@ -59,7 +58,7 @@ const Banner = ({ detailsObj }) => {
5958
}
6059

6160
Banner.propTypes = {
62-
detailsObj: PropTypes.obj,
61+
detailsObj: PropTypes.object,
6362
}
6463

6564
export default Banner

src/templates/article-latest.js

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react'
2+
import { getImage } from 'gatsby-plugin-image'
23
import styled from 'styled-components'
34
import PropTypes from 'prop-types'
45
import { graphql } from 'gatsby'
56
import Banner from '../pages/blog/components/_banner'
67
import { localize, WithIntl } from 'components/localization'
78
import Layout from 'components/layout/layout'
89
import { SEO, Show, Box, Flex, Container, SectionContainer } from 'components/containers'
9-
import { Header, Text } from 'components/elements'
10+
import { Header, QueryImage, Text } from 'components/elements'
1011
import device from 'themes/device'
1112

1213
const Background = styled.div`
@@ -40,7 +41,6 @@ const HeroContainer = styled(Container)`
4041
margin-bottom: 0;
4142
padding: 36px 16px 0;
4243
flex-direction: column;
43-
background-image: linear-gradient(var(--color-grey-8) 80%, var(--color-white) 20%);
4444
}
4545
`
4646
const HeroLeftWrapper = styled(Box)`
@@ -332,6 +332,7 @@ const convertDate = (date) => {
332332

333333
const ArticlesTemplate = (props) => {
334334
const post_data = props.data.directus.blog[0]
335+
335336
const footer_banner_data = post_data.footer_banners
336337
const side_banner_data = post_data.side_banners
337338

@@ -340,19 +341,16 @@ const ArticlesTemplate = (props) => {
340341
max_w_tablet: '320px',
341342
isExternal: true,
342343
redirectLink: side_banner_data.cta_url,
343-
imgSrcDesktop:
344-
'https://cms.deriv.com/assets/' + side_banner_data.banner_image.filename_disk,
344+
imgSrcDesktop: side_banner_data.banner_image.imageFile,
345345
}
346346

347347
const footer_banner_details = {
348348
max_w_value: '792px',
349349
max_w_tablet: '580px',
350350
isExternal: true,
351351
redirectLink: footer_banner_data.cta_url,
352-
imgSrcDesktop:
353-
'https://cms.deriv.com/assets/' + footer_banner_data.desktop_banner_image.filename_disk,
354-
imgSrcMobile:
355-
'https://cms.deriv.com/assets/' + footer_banner_data.mobile_banner_image.filename_disk,
352+
imgSrcDesktop: footer_banner_data.desktop_banner_image.imageFile,
353+
imgSrcMobile: footer_banner_data.mobile_banner_image.imageFile,
356354
}
357355

358356
return (
@@ -395,11 +393,9 @@ const ArticlesTemplate = (props) => {
395393
{post_data?.author && (
396394
<Flex ai="center" mt="40px" jc="flex-start">
397395
<WriterImage>
398-
<img
399-
src={
400-
'https://cms.deriv.com/assets/' +
401-
post_data?.author?.image?.filename_disk
402-
}
396+
<QueryImage
397+
data={getImage(post_data?.author?.image?.imageFile)}
398+
alt=""
403399
/>
404400
</WriterImage>
405401
<Box>
@@ -414,11 +410,9 @@ const ArticlesTemplate = (props) => {
414410
</HeroLeftWrapper>
415411
<HeroRightWrapper>
416412
<HeroImageContainer tabletL={{ mt: '24px' }}>
417-
<img
418-
src={
419-
'https://cms.deriv.com/assets/' +
420-
post_data?.main_image?.filename_disk
421-
}
413+
<QueryImage
414+
data={getImage(post_data?.main_image?.imageFile)}
415+
alt=""
422416
/>
423417
</HeroImageContainer>
424418
</HeroRightWrapper>
@@ -431,11 +425,9 @@ const ArticlesTemplate = (props) => {
431425
{post_data?.author && (
432426
<Flex ai="center" jc="flex-start">
433427
<WriterImage>
434-
<img
435-
src={
436-
'https://cms.deriv.com/assets/' +
437-
post_data?.author?.image?.filename_disk
438-
}
428+
<QueryImage
429+
data={getImage(post_data?.author?.image.imageFile)}
430+
alt=""
439431
/>
440432
</WriterImage>
441433
<Box>
@@ -510,12 +502,21 @@ export const query = graphql`
510502
id
511503
name
512504
image {
513-
filename_disk
505+
id
506+
imageFile {
507+
childImageSharp {
508+
gatsbyImageData
509+
}
510+
}
514511
}
515512
}
516513
main_image {
517514
id
518-
filename_disk
515+
imageFile {
516+
childImageSharp {
517+
gatsbyImageData
518+
}
519+
}
519520
}
520521
tags {
521522
id
@@ -529,18 +530,33 @@ export const query = graphql`
529530
cta_url
530531
name
531532
desktop_banner_image {
532-
filename_disk
533+
id
534+
imageFile {
535+
childImageSharp {
536+
gatsbyImageData
537+
}
538+
}
533539
}
534540
mobile_banner_image {
535-
filename_disk
541+
id
542+
imageFile {
543+
childImageSharp {
544+
gatsbyImageData
545+
}
546+
}
536547
}
537548
}
538549
side_banners {
539550
id
540551
cta_url
541552
name
542553
banner_image {
543-
filename_disk
554+
id
555+
imageFile {
556+
childImageSharp {
557+
gatsbyImageData
558+
}
559+
}
544560
}
545561
}
546562
}

0 commit comments

Comments
 (0)