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

astro-social-images

v0.4.1

Published

Social images generator for Astro

Downloads

9

Readme

astro-social-images

Add a component to generate Opengraph images to Astro, inspired by eleventy-plugin-social-images.

Unlike other solutions for Astro, it generates a svg that is then converted to a .png file through sharp. This means no headless browser, no third-party service etc.

It's all local which, well, can be good or bad depending on your needs, check out different options and see which one fits your project best!

Installing

npm install astro-social-images

Usage

---
import { SocialImage } from 'astro-social-images';
---

<SocialImage
  backgroundColor="#28262c"
  texts={[
    {
      content: 'My super title',
      attributes: { x: '55', y: '105', 'font-size': '70px', fill: '#fefffe' },
    },
  ]}
/>

will generate the following image:

Image with "My super title" written in the top-left corner

Alternatively, you can use it directly in Javascript in your Astro frontmatters (or any other files). The component uses this in the background so both ways are supported.

When using Typescript, you'll get nice completions and types in your editor when using this, which is pretty cool

import { generateSocialImage } from 'astro-social-images';

generateSocialImage({
  backgroundColor: '#28262c',
  texts: [
    {
      content: 'My super title',
      attributes: { x: '55', y: '105', 'font-size': '70px', fill: '#fefffe' },
    },
  ],
});

When used through JS, it won't generate the meta tags for you. Instead, the function will return an object containing the various properties you'll need to generate it yourself

You can add as many texts as you want and also images, see the documentation for more ways to customize your images

---
import { SocialImage } from 'astro-social-images';
---

<SocialImage
  backgroundColor="#28262c"
  images={[{ url: 'public/resized-social-card.png', attributes: { top: 375, left: 900 } }]}
  texts={[
    {
      content: 'Princesseuh',
      attributes: { x: '55', y: '105', 'font-size': '70px', fill: '#fefffe' },
    },
    {
      content: 'Introducing Astro: Ship Less JavaScript',
      attributes: { x: '50', y: '325', 'font-size': '40px', fill: '#fefffe' },
    },
  ]}
/>

Image with "Princesseuh" written in the top-left corner, "Introducing Astro: Ship Less JavaScript" a bit below and a ribbon (my personal website logo) in the bottom right corner

Complete Docs available here

FAQ

How to use custom fonts

Sharp doesn't load external fonts, the best way to get this working at the moment is by following the custom fonts instructions in the eleventy-plugin-generate-social-images README