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

nuxt-dynamic-images

v0.0.1

Published

Dynamiclly create social media preview images with Nuxt

Downloads

19

Readme

nuxt-dynamic-images

npm version npm downloads Github Actions CI semantic-release License

Features

  • Generate social media images from @nuxt/content documents
  • Design and build in any css framework you want

NOTE This only works with nuxt generate with ssr: true

Quick Setup

  1. Add nuxt-dynamic-images dependency to your nuxt project that already uses @nuxt/content.
# using yarn
yarn add nuxt-dynamic-images

# using npm
npm install nuxt-dynamic-images
  1. Add nuxt-dynamic-images to the buildModules section of nuxt.config.js
{
  buildModules: [
    // Simple usage
    'nuxt-dynamic-images',

    // With options
    ['nuxt-dynamic-images', { /* module options */ }]
  ]
}

Or a separate section dynamicImages for module options:

{
  buildModules: [
    // Simple usage
    'nuxt-dynamic-images',
  ],
  dynamicImages: {
    /* module options */
  }
}

Options

nuxt-dynamic-images has the following configuration options:

  • fields: Array<string> A list of all the fields nuxt-dynamic-images will generate from in the @nuxt/content folder. By default this is ['twitterImage', 'facebookImage'].

  • elSelector: string The DOM selector puppeteer will screenshot. By default this is #image.

  • publicPath: string The public path inside the nuxt public path where images will be saved. By default this is /images so generated images (by default) will have a url like /_nuxt/images/post-twitterImage.png.

  • puppeteerOptions?: any Raw options to give to puppeteer.launch(). By default this is an empty object.

Usage

For a complete usage example, see the example/ directory. But here is a short run down with the default configuration:

  1. Create some @nuxt/content files with image fields:
---

title: Example Blog Post!

facebookImage: /_public/social
twitterImage: /_public/social

---

Here is an example `@nuxt/content` document with a generated social media
images!
  1. Create a page at /_public/social:
<template>
  <div :class="${field}" id="image">
    <h1>{{ post.title }}</h1>
    <h2>{{ post.createdAt }}</h2>
  </div>
</template>

<script>
export default {
  async asyncData ({ $content, ssrContext }) {
    const { contentPath, contentField } = ssrContext
    const post = await $content(contentPath).fetch()

    return { post, field: contentField }
  }
}
</script>

<style scoped>
  .facebookImage {
    height: 628px;
    width: 1200px;
  }

  .twitterImage {
    height: 335px;
    width: 600px;
  }
</style>

TODO

Follow the GitHub issues for a more up to date status, but here is a general list of next steps:

  • Setup caching
  • Get some working setup when using nuxt dev
  • A better DX setup so you can view the images while designing them (no longer use ssrContext)
  • Documentation site
  • Try to figure out a more sane default configuration
  • Tests

Development

  1. Clone this repository
  2. Install dependencies using yarn install or npm install
  3. Start hacking away!

License

MIT License

Copyright (c)

Maintained by Blake Kostner