Skip to content

Instantly share code, notes, and snippets.

@kmelve
Created October 28, 2020 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmelve/5fc601fb52f594d89b05574d03cf9510 to your computer and use it in GitHub Desktop.
Save kmelve/5fc601fb52f594d89b05574d03cf9510 to your computer and use it in GitHub Desktop.
GIFs with Portable Text in Gatsby
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