Giter VIP home page Giter VIP logo

ogp-generater's Introduction

OGPanic Starter

OGPanic is a web service for generating beautiful and eye-catching og-images. As OGPanic uses headless chrome to render the images, there's basically no limits for what you can put inside the image. You can use web fonts, add beatiful gradients, and other fancy visuals effects that can be implemented by modern CSS and Javascript.

Developing the template

Register on https://ogpanic.com to get the API endpoint and API token.

Clone this repo and create a .env.development, or copy the example.env.example file to create one. Then fill in the API endpoint and token from OGPanic's dashboard.

OGPANIC_ENDPOINT=https://ogaas-app-1.ogpanic.com
OGPANIC_TOKEN=AabE@G-13

Run the following command to start developing your own template.

$ npm install
# npx ogaas develop --help, for more infomation
$ npm run develop

The template editor can be found at http://localhost:3000/editor to preview your og-image.

Template Editor

Source code structure

Templates are under ./src with each of them in different directories. The directory name will be used as the template's name for rendering the og-image.

e.g. The name of template under ./src/blog will be blog, and image generated by this template can be accessed via https://<endpoint>/og/blog/<id>.<jpeg|png>.

Under ./src/<template_name>, there will be 2 mandatory files: index.html, data.json. And you can add image and stylesheets and other resources if required.

Preparing the meta data

OGPanic allow you the specify only the id (slug) to access the generated og-image. Only who have uploaded the meta data of that id can determine what data to be shown in the image. data.json is the file to hold your mockup meta data when designing the template.

id will be used as the slug for the image and in data, you can put whatever you need for generating the final image.

{"id": "first-blog", "data": {"name": "A great blog"}}

In a production environment, it is recommended to upload the meta data when the page is created or updated. You can use the API or the command line tool for uploading data to OGPanic.

Filling data to the templates

This is the template html that is used to generate your og-image. With the example meta data above and the following template.

<h1>{{name}}</h1>

You will get the following. Use CSS to adjust the typo and position to make it look great!

<h1>A great blog</h1>

Upload meta data

When developing the templates with npm run develop, any changes to mockup data in data.json will automatically uploaded.

Use the following code to upload the data in production environment. You can either define OGPANIC_ENDPOINT, OGPANIC_TOKEN as environment variables or put then in the .env file.

import { uploadMeta } from 'ogaas-cli'

await uploadMeta([
    {id: "my-first-blog", data: {"name": "A awesome blog title"}}
])

You can also using the following command to upload.

# npx ogaas upload --help, for more infomation
$ npx ogaas upload <data.json>

Build & deploy the templates

You can deploy the templates by hitting DEPLOY TEMPLATES button on editor UI or by command line.

Build the templates.

# npx ogaas build --help, for more infomation
$ npm run build

Upload the built templates. Run npm run build before using this command.

note: Make sure you have the .env.production and correct API endpoint/token setup.

# npx ogaas deploy --help, for more infomation
$ npm run deploy

ogp-generater's People

Contributors

watsuyo avatar

Watchers

 avatar  avatar

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.