diff --git a/src/templates/challenge.js b/src/templates/challenge.js index f6a0fde3f..996a5218a 100644 --- a/src/templates/challenge.js +++ b/src/templates/challenge.js @@ -18,19 +18,21 @@ import PiCharacter from '../images/characters/PiGuy_2.mini.svg'; import SemiColonCharacter from '../images/characters/SemiColon_2.mini.svg'; const Challenge = ({ data }) => { - const { challenge, contributionPlaceholderImage, challengePlaceholderImage } = + const { challenge, coverImage, challengePlaceholderImage } = data; + // generic placeholder for challenge videos, collage of screenshots of challenge thumbnails const challengesPlaceholder = challengePlaceholderImage ? challengePlaceholderImage.childImageSharp.gatsbyImageData : null; - const contributionsPlaceholder = contributionPlaceholderImage - ? contributionPlaceholderImage.childImageSharp.gatsbyImageData + // cover image for the challenge, fallbacks to placeholder + const cover = coverImage + ? coverImage.childImageSharp.gatsbyImageData : challengesPlaceholder; return ( + image={cover}> { video={challenge} variant="cyan" url={`/challenges/${challenge.slug}`} - placeholderImage={contributionsPlaceholder} + placeholderImage={cover} /> @@ -66,7 +68,8 @@ const Challenge = ({ data }) => { @@ -190,7 +193,7 @@ export const query = graphql` } } } - contributionPlaceholderImage: file( + coverImage: file( sourceInstanceName: { eq: "challenges" } extension: { in: ["jpg", "png"] } relativeDirectory: { eq: $slug } diff --git a/src/templates/guide.js b/src/templates/guide.js index a6b71492c..2bf2510f4 100644 --- a/src/templates/guide.js +++ b/src/templates/guide.js @@ -166,15 +166,20 @@ const useLocalImages = (images) => { }; const Guide = ({ data, children }) => { - const { mdx, images } = data; + const { mdx, images, coverImage } = data; const localImages = useLocalImages(images.nodes); + // cover image for the guide, falls back to final placeholder image + const guideCover = coverImage + ? coverImage.childImageSharp.gatsbyImageData + : localImages['placeholder.png']; + return ( + image={guideCover}> { const { track, video, - contributionPlaceholderImage, + coverImage, videoPlaceHolderImage, challengePlaceholderImage } = data; - const contributionsPlaceholder = contributionPlaceholderImage - ? contributionPlaceholderImage.childImageSharp.gatsbyImageData + const placeholderMainTrackImage = + data.placeholderMainTrackImage.childImageSharp.gatsbyImageData; + const placeholderSideTrackImage = + data.placeholderSideTrackImage.childImageSharp.gatsbyImageData; + const trackPlaceholder = + track.type === 'main' + ? placeholderMainTrackImage + : placeholderSideTrackImage; + + // cover image for the video, falls back to final placeholder image + // (used as placeholder for contributions) + const contributionsPlaceholder = coverImage + ? coverImage.childImageSharp.gatsbyImageData : videoPlaceHolderImage ? videoPlaceHolderImage.childImageSharp.gatsbyImageData : null; + // generic placeholder for challenge videos, collage of screenshots of challenge thumbnails const challengesPlaceholder = challengePlaceholderImage.childImageSharp.gatsbyImageData; - const { trackPosition, isTrackPage } = pageContext; - + // cover image for the track, falls back to track placeholder image const trackImage = track.cover ? track.cover.file.childImageSharp.gatsbyImageData - : contributionsPlaceholder; + : trackPlaceholder; - const videoImage = video.cover - ? video.cover.file.childImageSharp.gatsbyImageData + // cover image for the video, falls back to track cover image + const videoImage = coverImage + ? coverImage.childImageSharp.gatsbyImageData : trackImage; + const { trackPosition, isTrackPage } = pageContext; + return (