Coder Social home page Coder Social logo

zeekrey / just-covid Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 0.0 2.03 MB

For all, who want less ๐Ÿ“ˆ and more ๐Ÿฑโ€๐Ÿ‘ค to describe the current COVID-19 situation. Stay safe. ๐Ÿ’Œ

Home Page: https://covid.krey.io

License: MIT License

TypeScript 59.33% JavaScript 40.67%
typescript nextjs vercel covid covid-19

just-covid's Introduction

Just C๐Ÿ˜ฒvid

For all, who want less ๐Ÿ“ˆ and more ๐Ÿฑโ€๐Ÿ‘ค to describe the current COVID-19 situation in Germany. Stay safe. ๐Ÿ’Œ

This is a really tiny project that plays with the awesome features provided by Vercel and Nextjs.

The main goal was to create a individual og:image per page. Inspired by repng I use playwright to create a actual image from a specified component:

// lib/imageFromComponent.ts
import { renderToStaticMarkup } from 'react-dom/server'
import { chromium } from 'playwright'

const baseCSS = `*{box-sizing:border-box}body{margin:0;font-family:system-ui,sans-serif}`

const imageFromComponent = async (
    Component: React.ReactElement,
    size: { width: number; height: number },
    filename: string
): Promise<Buffer> => {
    // Render the component to html
    const body = renderToStaticMarkup(Component)

    // Open a browser window and set the component with a unstyled body
    const browser = await chromium.launch()
    const page = await browser.newPage()
    await page.setContent(`<!DOCTYPE html><head>
    <meta charset="utf-8"><style>${baseCSS}</style>
    </head>
    <body style="display:inline-block">
    ${body}`)

    // Set the viewport size to the desired image size
    await page.setViewportSize(size)

    const result = await page.screenshot({
        path: filename,
        clip: {
            x: 0,
            y: 0,
            ...size,
        },
        omitBackground: true,
    })

    await browser.close()

    return result
}

export { imageFromComponent }

Caveats

As of writing this playwright needs a postinstall hook to work properly.This hook is not fired when next revalidates the page. If you want to use awesome ISG then you need somehow cache playwright or do something else.

Contribution

Do what ever you want. โค

Notes

This is an amalgamation of the 2 existing examples:

just-covid's People

Contributors

zeekrey avatar

Stargazers

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

Watchers

 avatar  avatar

just-covid's Issues

Fix static map issues

Some city maps are wrong or completly missing. Examples:

  • Freudenstadt (Landkreis) (missing)
  • Essen (missing)
  • Euskirchen (missing)
  • Augsburg (wrong)

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.