Created
October 28, 2020 19:58
-
-
Save kmelve/5fc601fb52f594d89b05574d03cf9510 to your computer and use it in GitHub Desktop.
GIFs with Portable Text in Gatsby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import Img from "gatsby-image"; | |
import { getFluidGatsbyImage } from "gatsby-source-sanity"; | |
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; | |
import { atomDark } from "react-syntax-highlighter/dist/esm/styles/prism"; | |
import iconLinksList from "./iconLinksList.js"; | |
import YouTube from "../components/YouTube.js"; | |
import getYouTubeID from "get-youtube-id"; | |
const sanityConfig = { projectId: "rx426fbd", dataset: "production" }; | |
export default { | |
types: { | |
code: props => { | |
return ( | |
<SyntaxHighlighter | |
language={props.node.language || "text"} | |
style={atomDark} | |
className="pre" | |
> | |
{props.node.code} | |
</SyntaxHighlighter> | |
); | |
}, | |
myAwesomeImage: props => { | |
const {extension, url} = props.node.asset | |
if (extension === "gif") { | |
return <img src={url} /> | |
} | |
const fluidProps = getFluidGatsbyImage( | |
props.node.asset, | |
{ maxWidth: 1024 }, | |
sanityConfig | |
); | |
return <Img fluid={fluidProps} />; | |
}, | |
iconLinksList, | |
iconLink: props => null, | |
ytVideo: props => <YouTube id={getYouTubeID(props.node.link)} />, | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment