Skip to content

Commit 4a8ced2

Browse files
committed
fix metadata images
1 parent dd74bfd commit 4a8ced2

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

src/templates/challenge.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ import PiCharacter from '../images/characters/PiGuy_2.mini.svg';
1818
import SemiColonCharacter from '../images/characters/SemiColon_2.mini.svg';
1919

2020
const Challenge = ({ data }) => {
21-
const { challenge, contributionPlaceholderImage, challengePlaceholderImage } =
21+
const { challenge, coverImage, challengePlaceholderImage } =
2222
data;
23+
// generic placeholder for challenge videos, collage of screenshots of challenge thumbnails
2324
const challengesPlaceholder = challengePlaceholderImage
2425
? challengePlaceholderImage.childImageSharp.gatsbyImageData
2526
: null;
26-
const contributionsPlaceholder = contributionPlaceholderImage
27-
? contributionPlaceholderImage.childImageSharp.gatsbyImageData
27+
// cover image for the challenge, fallbacks to placeholder
28+
const cover = coverImage
29+
? coverImage.childImageSharp.gatsbyImageData
2830
: challengesPlaceholder;
2931
return (
3032
<Layout
3133
title={challenge.title}
3234
description={challenge.description}
33-
image={contributionsPlaceholder}>
35+
image={cover}>
3436
<Breadcrumbs
3537
className={css.breadcrumbs}
3638
breadcrumbs={[
@@ -49,7 +51,7 @@ const Challenge = ({ data }) => {
4951
video={challenge}
5052
variant="cyan"
5153
url={`/challenges/${challenge.slug}`}
52-
placeholderImage={contributionsPlaceholder}
54+
placeholderImage={cover}
5355
/>
5456
</main>
5557

@@ -66,7 +68,8 @@ const Challenge = ({ data }) => {
6668

6769
<PassengerShowcasePanel
6870
contributions={challenge.showcase}
69-
placeholderImage={contributionsPlaceholder}
71+
// fallback to challenge cover image if no showcase cover image exists
72+
placeholderImage={cover}
7073
submitButtonState={{ track: 'challenges', video: challenge.slug }}
7174
/>
7275

@@ -190,7 +193,7 @@ export const query = graphql`
190193
}
191194
}
192195
}
193-
contributionPlaceholderImage: file(
196+
coverImage: file(
194197
sourceInstanceName: { eq: "challenges" }
195198
extension: { in: ["jpg", "png"] }
196199
relativeDirectory: { eq: $slug }

src/templates/guide.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,20 @@ const useLocalImages = (images) => {
166166
};
167167

168168
const Guide = ({ data, children }) => {
169-
const { mdx, images } = data;
169+
const { mdx, images, coverImage } = data;
170170

171171
const localImages = useLocalImages(images.nodes);
172172

173+
// cover image for the guide, falls back to final placeholder image
174+
const guideCover = coverImage
175+
? coverImage.childImageSharp.gatsbyImageData
176+
: localImages['placeholder.png'];
177+
173178
return (
174179
<Layout
175180
title={mdx.frontmatter.title}
176181
description={mdx.frontmatter.description}
177-
image={localImages['placeholder.png']}>
182+
image={guideCover}>
178183
<Breadcrumbs
179184
className={css.breadcrumbs}
180185
breadcrumbs={[
@@ -243,6 +248,15 @@ export const query = graphql`
243248
}
244249
}
245250
}
251+
coverImage: file(
252+
sourceInstanceName: { eq: "guides" }
253+
extension: { in: ["jpg", "png"] }
254+
name: { eq: $slug }
255+
) {
256+
childImageSharp {
257+
gatsbyImageData
258+
}
259+
}
246260
}
247261
`;
248262

src/templates/track-video.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,32 @@ const Track = ({ pageContext, data }) => {
2323
const {
2424
track,
2525
video,
26-
contributionPlaceholderImage,
26+
coverImage,
2727
videoPlaceHolderImage,
2828
challengePlaceholderImage
2929
} = data;
3030

31-
const contributionsPlaceholder = contributionPlaceholderImage
32-
? contributionPlaceholderImage.childImageSharp.gatsbyImageData
31+
// cover image for the video, falls back to final placeholder image
32+
// used as a placeholder for showcase
33+
const contributionPlaceholder = coverImage
34+
? coverImage.childImageSharp.gatsbyImageData
3335
: videoPlaceHolderImage
3436
? videoPlaceHolderImage.childImageSharp.gatsbyImageData
3537
: null;
3638

39+
// generic placeholder for challenge videos, collage of screenshots of challenge thumbnails
3740
const challengesPlaceholder =
3841
challengePlaceholderImage.childImageSharp.gatsbyImageData;
3942

40-
const { trackPosition, isTrackPage } = pageContext;
41-
43+
// cover image for the track, falls back to video cover image and then to final placeholder image
4244
const trackImage = track.cover
4345
? track.cover.file.childImageSharp.gatsbyImageData
44-
: contributionsPlaceholder;
46+
: contributionPlaceholder;
4547

46-
const videoImage = video.cover
47-
? video.cover.file.childImageSharp.gatsbyImageData
48-
: trackImage;
48+
// cover image for the video, falls back to track cover image
49+
const videoImage = contributionPlaceholder ? contributionPlaceholder : trackImage;
50+
51+
const { trackPosition, isTrackPage } = pageContext;
4952

5053
return (
5154
<Layout
@@ -105,7 +108,7 @@ const Track = ({ pageContext, data }) => {
105108

106109
<PassengerShowcasePanel
107110
contributions={video.showcase}
108-
placeholderImage={contributionsPlaceholder}
111+
placeholderImage={contributionPlaceholder}
109112
headerType={isTrackPage ? 'h3' : 'h2'}
110113
submitButtonState={{
111114
track: video.canonicalTrack?.slug ?? 'challenges',
@@ -294,7 +297,7 @@ export const query = graphql`
294297
}
295298
}
296299
}
297-
contributionPlaceholderImage: file(
300+
coverImage: file(
298301
sourceInstanceName: { eq: $source }
299302
extension: { in: ["jpg", "png"] }
300303
relativeDirectory: { eq: $videoSlug }

0 commit comments

Comments
 (0)