Giter Club home page Giter Club logo

v-satori's Introduction

v-satori

Generate a satori-friendly VDOM from a Vue component. Uses satori-html.

Installion

npm install satori v-satori

Usage

Nuxt 3

export default defineNuxtConfig({
  modules: ['v-satori/nuxt']
})
<script setup>
defineProps({
  title: String,
  website: String,
})
</script>

<template>
  <div tw="h-full w-full flex items-start justify-start border border-blue-500 border-[12px] bg-gray-50">
    <div tw="flex items-start justify-start h-full">
      <div tw="flex flex-col justify-between w-full h-full'">
        <h1 tw="text-[80px] p-20 font-black text-left">
          {{ title }}
        </h1>
        <div tw="text-2xl pb-10 px-20 font-bold mb-0">
          {{ website }}
        </div>
      </div>
    </div>
  </div>
</template>
// server/api/og.ts

import { satori } from 'v-satori'
import Image from '@/components/Image.vue'
// https://github.com/wobsoriano/unplugin-font-to-buffer
import Roboto from '@/lib/fonts/Roboto-Regular.ttf'

export default eventHandler(async (event) => {
  const query = getQuery(event)

  const svg = await satori(Image, {
    props: {
      title: query.title,
      website: query.website
    },
    width: 1200,
    height: 630,
    fonts: [{
      name: 'Roboto',
      data: Roboto,
      weight: 400,
      style: 'normal',
    }]
  })

  setHeader(event, 'Content-Type', 'image/svg+xml')

  return svg
})

You can then create new dynamic images by passing the following parameters to the API endpoint:

<script setup>
const title = 'OG Image Generator using Nuxt and Satori'
const website = 'v3.nuxtjs.org'
</script>

<template>
  <Head>
    <Meta property="og:image" :content="`/api/og?title=${title}&website=${website}`" />
  </Head>
</template>

Output:

License

MIT

v-satori's People

Contributors

wobsoriano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

v-satori's Issues

Nuxt

Hi,

I followed your Nuxt 3 example, is it possible to have Satori return a PNG, as browsers don't seem to return the SVG output.

Thanks

Ability to convert to PNG?

Hey,

so it seems that platforms like Twitter don’t support the SVG output.

would it be possible to convert the SVG output to binary or something to output as an image?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.