Skip to content

OGP Image generation #21

Description

@rokuosan

Feature overview

Generate an OGP image alongside article generation (generate).

Reason

I thought it would be convenient to be able to generate OGP images using this tool alone, without relying on an external OGP generation tool.

Design

The design is authored as an HTML file, with placeholders for injected values written using Go's text/template syntax (e.g. {{ .Title }}). Go reads this file, sets the variables, expands the template, renders it with a headless browser, and outputs the result as a JPEG.

  • Output size is a fixed value (1200x630 is the target — this displays correctly on major SNS cards such as Twitter)
  • go-rod will be used as the renderer
    • chromedp requires Chrome/Chromium to already be installed in the execution environment
    • playwright-go requires a separate playwright install step to fetch browser binaries
    • go-rod's launcher package can automatically download and cache the required Chromium version locally, so it works with a go run workflow without any extra setup
    • For CI/Docker environments that already have Chromium available, an option (env var or flag) to explicitly point to a browser binary will be provided

Milestones

  • 1. Create an OGP image generation pkg
    • Create a new pkg that loads a template (HTML), expands it with variables, renders it, and outputs a JPEG
    • Data passed to the template is defined as its own dedicated struct, separate from core.Article, so this pkg does not depend on core
      • For now a minimal set of fields (Title / Author / Date / Category / Tags) is enough — management-only data specific to Article is not included
      • Should be built with extensibility in mind so fields can be added later without much friction
  • 2. Add a subcommand to generate an OGP image from a local Markdown file
    • Subcommand name: ogimage (tentative)
    • Reads a local Markdown file (one generated by this tool), binds it to core.Article, then generates the image using the pkg from Milestone 1
      • This sets up Milestone 3, where the image is generated directly from Article
    • Output goes to the image output directory configured in gic.config.yaml
    • Filename is fixed as ogp.jpeg, placed in the target article's directory
  • 3. Integrate into the generate command
    • Add a --with-ogimage flag to generate; when set, OGP image output happens at the end of the article generation flow (fetch issue → download/place images → convert)
    • Making this opt-in preserves the existing simple execution experience for users who don't use a headless browser

Open questions / Not yet decided

  • Whether to make the template path, output size, etc. configurable is left for later (fixed values are fine for now)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions