0.9.9 • Published 3 months ago

nuxt-dsi v0.9.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Nuxt DSI (Dynamic Social Images)

npm wakatime

Sets up an endpoint (default: /socialImage) that takes a path GET parameter and will generate a dynamic social share image based on specified meta tags, and other configuration.

The path parameter tells the module what path on the website you are rendering the image for, i.e.: /socialImage?path=/blog/my-first/post

Generated images are cached, and the cache is cleared when your application restarts.

This module works well with nuxt-head-ex :)

Installation

yarn add nuxt-dsi

Add the module to your nuxt.config.ts:

modules: ['nuxt-dsi'],

Configuration

Add the module to your nuxt.config.ts and add optional configuration:

import {DSIHandler} from '~playground/src/dsi-handler.get.ts'

export default defineNuxtConfig({
  modules: [
    'nuxt-dsi'
  ],
  dsi: {
    // where the image endpoint will listen
    path: '/socialImage',
    // static text placed at the top of the image
    fixedText: 'Nuxt: Dynamic Social Images',
    // set your custom render handler/function
    customHandler: DSIHandler,
    // set up your custom fonts
    fonts: [
      { path: 'playground/fonts/ConnectionIi-2wj8.otf', 
        options: { family: 'connectionii' } },
      { path: 'playground/fonts/Barlow/Barlow-thin.ttf', 
        options: { family: 'barlowthin', fontWeight: '100' } }
    ]
  }
})

In your app.vue, set up your default og:image reflectively:

<script setup>
  import {useHead} from "#head"
  import {useRoute, useRuntimeConfig} from "#app";

  const config = useRuntimeConfig().public.dsi
  const route = useRoute()
  
  useHead({
    meta: [
        {
          property: 'og:image',
          content: () => `${config.path}?path=${route.fullPath}`
        }
    ]
  })

</script>

See fabric's registerFont method to learn more about configuring fonts.

Extending / Customization

You can check out the playground/src/dsi-handler.get.ts for an example on how to add your own render function that overrides the default, giving you complete control over what your cards look like!

If you want to use 'clean' versions of strings (i.e. a barebones title like "Homepage" instead of "MySite: Homepage"), you can specify the meta tag as such:

useHead({
  title: 'This is my Test Page',
  meta:[
    {name: 'clean:title', content: "Test Page" },
  ]
})

Examples

Development

  • Run npm run dev:prepare to generate type stubs.
  • Use npm run dev to start playground in development mode.

Credits

Made with 💚 by Larry Williamson / @l422y

0.9.7

3 months ago

0.9.9

3 months ago

0.9.6

3 months ago

0.9.5

3 months ago

0.8.9

6 months ago

0.7.10

6 months ago

0.7.9

6 months ago

0.9.4

6 months ago

0.9.3

6 months ago

0.7.5

6 months ago

0.7.8

6 months ago

0.7.7

6 months ago

0.8.12

6 months ago

0.8.11

6 months ago

0.8.13

6 months ago

0.8.10

6 months ago

0.9.0

6 months ago

0.8.1

6 months ago

0.7.2

6 months ago

0.8.0

6 months ago

0.7.1

6 months ago

0.9.2

6 months ago

0.8.3

6 months ago

0.7.4

6 months ago

0.9.1

6 months ago

0.8.2

6 months ago

0.7.3

6 months ago

0.7.0

8 months ago

0.4.1

1 year ago

0.5.2

1 year ago

0.6.0

1 year ago

0.5.1

1 year ago

0.4.0

1 year ago

0.3.5

1 year ago

0.3.22

1 year ago

0.3.12

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.52

1 year ago

0.3.51

1 year ago

0.3.21

1 year ago

0.2.23

1 year ago

0.2.21

1 year ago

0.1.21

1 year ago

0.0.21

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago