It’s now posible to generate preview images for social networks (Twitter, Slack, LinkedIn…).

twitter card

This great idea come from a conversation I had with Luciano Mammino (aka @Loige). I basically took 85% of his code. Thanks Luciano 😊

How to do it?

  1. Open 2 terminals:

    # Terminal 1
    npm run dev
    
    # Terminal 2
    npm run generatePostPreviewImages
    # ..you can also specify the url (if different from http://localhost:8000/)
    npm run generatePostPreviewImages http://localhost:1234/
  2. In the post’s header, add the generated images:

    title: My blog post
    # ...
    imageShare: ./social-media-card-generator-share.png

Gatsby will first create extra url suffixed by /image_share (i.e. http://localhost:8000/gatsby-starter-morning-dew-v1-1/image_share). Then, Pupetter will take a snapshot and add it to your post folder.

💡Quick tip: If you want to recreate this pictures

# delete all share images
find ./content -name "*-share.png" -type f -delete

If you want to skip the file generation for some posts, add generate-card: false to the post’s header.

---
title: My blog post
# ...
generate-card: false
---

About the author

For the last decade, Maxence Poutord has worked with a variety of web technologies. He is currently focused on front-end development. On his day to day job, he is working as a senior front-end engineer at VSware. He is also an occasional tech speaker and a mentor. As a digital nomad, he is living where the WiFi and sun are 😎
Do you want to know more? Visit my website!