|
Hi! I'm looking for a way to define page's social-image meta tag based on the image linked on the first img tag of the html's main section. As I'm using the eleventy-img plugin for all images of my site, this seems to be an easy way to solve this. In isolation, this piece of code would solve the problem: I believe that this code (or another of the same type) should be applied after image conversions and with the html already formed by the build process. The result I expect is that the I'm not very familiar with Node.js and the Eleventy build process, so I'm wondering what's the best way to solve this process. I appreciate any suggestions. |
Replies: 1 comment 8 replies
|
I'd start by looking at https://www.11ty.dev/docs/config/#transforms. |
I'd start by looking at https://www.11ty.dev/docs/config/#transforms.
Transforms run pretty late in the build pipeline when the HTML should be "complete".
Then, check whether the current file being transformed is an .html template, and if so, use something like https://cheerio.js.org/ to query the markup for your first
main imgtag and then append your<meta property="og:image" content="{{ something }}"/>tag into the<head>and then return the new HTML DOM which will be written to the disk.