Open the chart pictures. These small images will appear when your site is shared on social media. My site sites were… bad. My default was to use an equally huge, boring product image for everything – that didn’t add value and just messed up all the feeds (sorry!). I wanted to make them better and I did.
When building a screenshot cloud service It became apparent to 11ty.deville that I should increase the Open Graph size to use screenshots as Open Graph images. You can see this enabled on the Eleventy document pages:
- Navigate to something
- When the screenshot service is enabled, it is just one line for a custom Open Graph image:
<meta property="og:image" content="https://v1.screenshot.11ty.dev/https%3A%2F%2Fwww.11ty.dev%2Fdocs%2F/opengraph/">
- The image on the social card looks like this:
Due to the amount of work required for the installation, it was totally worth it (one
<meta>!). However, I wanted to take it to the next level on my personal blog (the long-term goal might be to convince my colleagues to use something like this netlify.com 😅).
In the past, I tried it a bit Eleventy Image SVG raster feature (through
sharp), but that was not what I wanted. Its advantage was that it was much faster than HTML – based methods (usually based on Puppeteer), but in the end I had to read a bunch of handwritten SVGs to make it look like I wanted to look like. I admit I’m not as productive in SVG’s handwriting as I’d like.
Based on these experiences, I decided to customize the page on my site (source code), which is repeated on every blog post and could serve as the target of my screenshot service. There were a couple of benefits to this:
- I can use any existing HTML / CSS / JS / fonts that are already in use on my site. This means, among other things, fake browser chrome, custom Twitter avatars, Lighthouse points, popularity ratings!
- I don’t have to drive Puppeteer locally. I try to avoid this whenever possible – it’s awesome, but it slows down construction (a lot).
For example, each individual blog post has its own Open Graph image page
/opengraph/web/automatic-opengraph/ (Correct warning: this page does not use responsive web design principles. It is specially designed for 1200 × 630 aspect ratio).
If I want a custom wallpaper for a single open image image, add the front of the image with the URL:
Next, in my ninety-layout master file (source code) I point to the Open Graph page for each blog post towards the screenshot service to take a picture:
It looks like this:
I wanted the image to include the message title, avatar, Post Date, and page URL.
For bonus metadata, here are the Lighthouse points (is updated regularly through Speedlife), number of web pages and even page weight (eg 226 KiB, including Speedlify):
Devulation of DevTools
I added a custom emulated device inside Chrome Devtools specifically for Open Graph image formats to test the layouts.
Social card preview
I added a little
<details> at the bottom of each blog post so I can test social card image preview. I’ll probably translate this into a link-based sharing widget at some point or link it to an existing one Retweet for sharing.
Breaking the On-demand Builder cache
The Eleven screenshot services is a standalone project that uses On-demand Builders to cache screenshot content in a Netlify CDN file. That cache is pretty sticky. The easiest way to clear the cache is to start the screenshot service structure in Netlify, but it will reset the cache all screenshots saved by the service that are too heavy. There has been a general request for a more granular Netlify API to reset the cache parts, but during the development of this project I realized that we can handle this manually on the application side with the help of our old friend, cache remover URL.
If the old URL looked like this
https://v1.screenshot.11ty.dev/https%3A%2F%2Fwww.zachleat.com%2Fopengraph%2Fweb%2Fcomprehensive-webfonts%2F/opengraph/, I can add an arbitrary cache removal key to its end (with an underscore prefix to identify it in any URL).
If I have created a key with today’s date (e.g.
https://v1.screenshot.11ty.dev/https%3A%2F%2Fwww.zachleat.com%2Fopengraph%2Fweb%2Fcomprehensive-webfonts%2F/opengraph/_20210803/), it creates new images every day without the need for the screenshot service to clear the entire cache. (Some a related discussion on Twitter)