npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@my-ginger-pussy/eleventy-social-images

v1.0.2

Published

Dynamically generate social media images for your Eleventy pages, suitable for Eleventy V3 only.

Downloads

11

Readme

Eleventy Plugin: Generate Social Images (using SVG)

Dynamically generate social media images for your Eleventy (11ty) pages. This plugin uses SVG & does not depend on Puppeteer!

This version will only run with Eleventy 3.0.0 +


Introduction

This plugin provides an 11ty ShortCode that can be used to automatically generate social images in your Eleventy website.

For example:

{% GenerateSocialImage "Eleventy plugin for generating social images (using SVG)" %}

will generate the following social image (website, email address and author-image are set during configuration):

The social image is first created as SVG and then converted to PNG using Sharp.

How does it work?

  • Generates the image using SVG and then converts it into PNG using Sharp.
  • Custom logic to wrap the title line in SVG (as Sharp does not support SVG foreignObject).
  • Adds an author/promo image using Sharp composite (as Sharp does not support external image in SVG).

Installation and Usage

STEP 1: Install the package

npm i @fat-buddha-designs/eleventy-social-images/

STEP 2: Include it in your .eleventy.js config file

const generateSocialImages = require("@fat-buddha-designs/eleventy-social-images/");

module.exports = (eleventyConfig) => {
  eleventyConfig.addPlugin(generateSocialImages, {
    promoImage: "./src/img/my_profile_pic.jpg",
    outputDir: "./_site/img/preview",
    urlPath: "/img/preview",
    siteUrl: "Website ~ https://fatbuddhadesigns.co.uk/",
    siteEmail: "Email ~ [email protected]/",
    titleColor: '#dfa634',
    bgColor: '#fff',
    terminalBgColor: '#333',
    lineBreakAt: '48'
  });
};

or for ESM

const generateSocialImages from "@fat-buddha-designs/eleventy-social-images/";

export default async function (eleventyConfig) {
  eleventyConfig.addPlugin(generateSocialImages, {
    promoImage: "./src/img/my_profile_pic.jpg",
    outputDir: "./_site/img/preview",
    urlPath: "/img/preview",
    siteUrl: "Website ~ https://fatbuddhadesigns.co.uk/",
    siteEmail: "Email ~ [email protected]/",
    titleColor: '#dfa634',
    bgColor: '#fff',
    terminalBgColor: '#333',
    lineBreakAt: '48'
  });
};

Step 3: Use in your template

For example, in your base.njk template file, use it in the <head> for generating social image meta tags:

<meta property="og:image" content="{% GenerateSocialImage title %}" />
<meta name="twitter:image" content="{% GenerateSocialImage title %}" />

Config Options

| Option | Type | Default | Description | | ----------- | ------ | ------------- |-------------| | promoImage | string | | Path to a promo Image (ideally, circular) that will be embedded in the social-images | | outputDir | string | "./_site/img/preview" | Project-relative path to the output directory where images will be generated | | urlPath | string | "/img/preview" | A path-prefix-esque directory for the <img src> attribute. e.g. /img/ for <img src="/img/MY_IMAGE.jpeg"> | | siteUrl | string | | The website url to show on the social-image | | siteEmail | string | | The website email address to show on the social-image | | titleColor | string | "white" | The color of the page-title | | bgColor | string | | Optional background color. Otherwise, shows the gradient pattern | | terminalBgColor| string | "#404040" | Background color of the terminal window design | | hideTerminal | boolean | false | If true, hides the terminal window design behind the title | | customSVG | string | | Custom SVG code to be added to the image. Use this to add your own design or text anywhere on the image | | customFontFilename | string | | Filename of custom local font used for title (see Custom Fonts) | | lineBreakAt | number | 35 | Maximum row length for wrapping the title. Required because SVG does not have auto-wrapping text. Should depends on the font used |

Custom Fonts

The Sharp library uses librsvg that uses fontconfig to load external fonts. Therefore, the following steps are required:

  1. Download your font file in project sub-folder. Eg: ./fonts/sans.ttf

  2. Create a file fonts.conf with the following content:

  1. Setup the following environment variable on your build server (eg: Netlify):

    FONTCONFIG_PATH=.

Credits