Skip to content

Commit bd0c33c

Browse files
authored
Merge pull request #1310 from dipamsen/fix-meta
Fix metadata images
2 parents 1553a04 + 47c0ed8 commit bd0c33c

File tree

3 files changed

+67
-18
lines changed

3 files changed

+67
-18
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: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,44 @@ 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+
const placeholderMainTrackImage =
32+
data.placeholderMainTrackImage.childImageSharp.gatsbyImageData;
33+
const placeholderSideTrackImage =
34+
data.placeholderSideTrackImage.childImageSharp.gatsbyImageData;
35+
const trackPlaceholder =
36+
track.type === 'main'
37+
? placeholderMainTrackImage
38+
: placeholderSideTrackImage;
39+
40+
// cover image for the video, falls back to final placeholder image
41+
// (used as placeholder for contributions)
42+
const contributionsPlaceholder = coverImage
43+
? coverImage.childImageSharp.gatsbyImageData
3344
: videoPlaceHolderImage
3445
? videoPlaceHolderImage.childImageSharp.gatsbyImageData
3546
: null;
3647

48+
// generic placeholder for challenge videos, collage of screenshots of challenge thumbnails
3749
const challengesPlaceholder =
3850
challengePlaceholderImage.childImageSharp.gatsbyImageData;
3951

40-
const { trackPosition, isTrackPage } = pageContext;
41-
52+
// cover image for the track, falls back to track placeholder image
4253
const trackImage = track.cover
4354
? track.cover.file.childImageSharp.gatsbyImageData
44-
: contributionsPlaceholder;
55+
: trackPlaceholder;
4556

46-
const videoImage = video.cover
47-
? video.cover.file.childImageSharp.gatsbyImageData
57+
// cover image for the video, falls back to track cover image
58+
const videoImage = coverImage
59+
? coverImage.childImageSharp.gatsbyImageData
4860
: trackImage;
4961

62+
const { trackPosition, isTrackPage } = pageContext;
63+
5064
return (
5165
<Layout
5266
title={isTrackPage ? track.title : video.title}
@@ -294,7 +308,7 @@ export const query = graphql`
294308
}
295309
}
296310
}
297-
contributionPlaceholderImage: file(
311+
coverImage: file(
298312
sourceInstanceName: { eq: $source }
299313
extension: { in: ["jpg", "png"] }
300314
relativeDirectory: { eq: $videoSlug }
@@ -324,6 +338,24 @@ export const query = graphql`
324338
gatsbyImageData
325339
}
326340
}
341+
placeholderMainTrackImage: file(
342+
sourceInstanceName: { eq: "main-tracks" }
343+
extension: { in: ["jpg", "png"] }
344+
name: { eq: "placeholder" }
345+
) {
346+
childImageSharp {
347+
gatsbyImageData
348+
}
349+
}
350+
placeholderSideTrackImage: file(
351+
sourceInstanceName: { eq: "side-tracks" }
352+
extension: { in: ["jpg", "png"] }
353+
name: { eq: "placeholder" }
354+
) {
355+
childImageSharp {
356+
gatsbyImageData
357+
}
358+
}
327359
}
328360
`;
329361

0 commit comments

Comments
 (0)