Skip to content

agneym/generate-og-image

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Open Graph Image Generator

A GitHub Action that generates Open Graph images from your markdown files. It runs on PRs, reads frontmatter config, and creates images for your blog posts.

I built this because I was tired of either having no OG images or manually creating them for every post. This just automates it based on your existing markdown.

Setup

Add to your workflow:

name: "Generate OG Images"
on: pull_request

jobs:
  generate_og_job:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: BoyWithSilverWings/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GITHUB_CONTEXT: ${{ toJson(github) }}
        with:
          path: src/images/post-images/

Then add to your markdown frontmatter:

---
ogImage:
  title: "Things you don't know"
  subtitle: "There must be something"
  imageUrl: "https://example.com/image-url.jpg"
  background: "yellow"
  fontColor: "rgb(0, 0, 0)"
  fontSize: "100%"
---

Configuration

Frontmatter Props

Props Description Required Default
title Title text
subtitle Subtitle text
imageUrl Image or emoji URL
background Background color/gradient/image
fontColor Text color
fontSize Font size 100%
fileName Output filename kebab-cased title

Works with PRs and .md/.mdx files.

Repository Props

Configure in your workflow file:

Props Description Required
path Where to save images
commitMsg Commit message
background Default background
fontColor Default text color
fontSize Default font size
componentUrl Custom web component
botComments Disable comments ("no")

Frontmatter overrides repository settings.

Examples

Gradient background:

background: "linear-gradient(to right, #ec008c, #fc6767)"

Image background:

background: "url(https://example.com/image.png)"

Emoji instead of image:

imageUrl: "🚀"

Disable bot comments:

botComments: "no"

Customization

The default web component is here. Replace it with your own:

componentUrl: "https://your-custom-component.js"

Contributing

See docs

Credits

About

Generate open graph images with Github Action from Markdown files

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5