Created
January 6, 2020 20:35
-
-
Save darisi/1f0ce71a2be1f447bd76df7d71803972 to your computer and use it in GitHub Desktop.
Sanity, Gatsby - Custom Block Style
This file contains hidden or 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"; | |
const Lead = ({ children }) => { | |
return <p className="text-2xl text-gray-600">{children}</p>; | |
}; | |
export default Lead; |
This file contains hidden or 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 Figure from "./Figure"; | |
import Lead from "./Lead"; | |
const serializers = { | |
types: { | |
authorReference: ({ node }) => <span>{node.author.name}</span>, | |
mainImage: Figure, | |
block: ({ node, children }) => { | |
switch (node.style) { | |
case "h1": | |
return <h1>{children}</h1>; | |
case "h2": | |
return <h2>{children}</h2>; | |
case "h3": | |
return <h3>{children}</h3>; | |
case "h4": | |
return <h4>{children}</h4>; | |
case "blockquote": | |
return <blockquote>{children}</blockquote>; | |
case "lead": | |
return <Lead children={children} />; | |
default: | |
return <p>{children}</p>; | |
} | |
}, | |
}, | |
}; | |
export default serializers; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment