@andrioid/gatsby-plugin-social-card
v0.5.6
Published
Generates social cards for your markdown posts and adds a field so you can reference them in your meta-tags.
Downloads
8
Maintainers
Readme
gatsby-plugin-social-card
Automatically parses your posts and generates social cards for Twitter, Slack, Facebook and other sites.
To learn more about social-cards in general, check out open graph, twitter cards and this CSS tricks article on meta-tags for social.
Current Status: Beta
I'm using this for andri.dk and it works for me, both locally and for Netlify builds. Contact me on Twitter if you're testing this and it fails.
Only works for remark nodes at the moment.
Features
Designs
There are two design available now, "card" and "default". But we can expand that later.
Custom Backgrounds
You can put a cover frontmatter on your post, and we'll use that. Otherwise, we'll use a default-background that you can specify or if that fails, we'll use a fallback one.
Custom Author image
If specified, an author image is shown on the image. That is also configurable.
Powerd by SVG, React and Sharp
We use the same underlying library that powers gatsby-images to convert our React generated SVG files into images.
Install
yarn add @andrioid/gatsby-plugin-social-card
# or npm install --save @andrioid/gatsby-plugin-social-card
How to use
Configure our site to use the plugin by editing gatsby-config.js
. You don't need to specify options.
plugins: [
{
'@andrioid/gatsby-plugin-social-card',
}
]
If you want to customise the look of the cards, try these options.
plugins: [
{
resolve: '@andrioid/gatsby-plugin-social-card',
options: {
// ommit to skip
authorImage: './static/img/coffee-art.jpg',
// image to use when no cover in frontmatter
backgroundImage: './static/img/hvitserkur.JPG',
// author to use when no auth in frontmatter
defaultAuthor: 'Andri Óskarsson',
// card design
design: 'default' // 'default' or 'card'
}
}
]
Then you need to add the meta tags to your site. For a more complete example of meta tags, check out seo.js from Kent C. Dodds.
import Helmet from 'react-helmet'
const image = node.frontmatter.socialcard
export const SEO = ({ postData, frontmatter = {}, metaImage, isBlogPost }) => (
<Helmet>
{/* Your other meta tags... */}
<meta name="image" content={image} />
<meta property="og:image" content={image} />
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content={image} />
</Helmet>
)
Pitfalls
Fonts
We use sharp to convert our SVG images to JPG. The means that the fonts available to you are limited to those of the build-machine.
VIPS image library
Depending on your installation, SVG support in libvips (used by Sharp) might be missing.
It needs to be built with JPEG and SVG support.