Skip to content

feat: add OGP image rendering package (pkg/ogimage) - #158

Merged
rokuosan merged 8 commits into
rokuosan:mainfrom
rokuosanai:feat/ogp-image-rendering-pkg
Jul 29, 2026
Merged

feat: add OGP image rendering package (pkg/ogimage)#158
rokuosan merged 8 commits into
rokuosan:mainfrom
rokuosanai:feat/ogp-image-rendering-pkg

Conversation

@rokuosanai

Copy link
Copy Markdown
Contributor

Summary

Implements milestone 1 of #21 — creates a new pkg/ogimage package for rendering OGP images from HTML templates using a headless Chromium browser.

Changes

  • pkg/ogimage/ogimage.goOGPData struct (Title, Author, Date, Category, Tags) independent of core.Article
  • pkg/ogimage/renderer.go — go-rod based renderer with:
    • Embedded default HTML template (modern dark-themed OGP card design)
    • 1200×630 JPEG output via headless Chromium
    • GIC_CHROMIUM_BIN env var support for explicit browser binary
    • Auto-download of Chromium via go-rod launcher when no binary specified
    • Custom template support via NewRendererWithTemplate
  • pkg/ogimage/template.html — Embedded default OGP HTML template
  • Tests — Unit tests for renderer creation, template execution, Chromium bin resolution, and integration test skeleton

Closes #153

- Define OGPData struct for template values (Title, Author, Date, Category, Tags)
  independent of core.Article
- Embed default OGP HTML template with modern dark-themed design
- go-rod based headless browser renderer outputting 1200x630 JPEG
- Support GIC_CHROMIUM_BIN env var and explicit browser binary path
- go-rod launcher auto-downloads Chromium when no binary is specified

Closes rokuosan#153
@rokuosan

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 94fcf23a6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/ogimage/renderer.go Outdated
Comment thread pkg/ogimage/renderer.go Outdated
Comment thread pkg/ogimage/renderer.go Outdated
Comment thread pkg/ogimage/renderer.go Outdated
- P1: Switch from text/template to html/template to escape user-authored
  metadata (XSS prevention)
- P2: Bind context to launcher and browser so cancellation propagates
  properly to Chromium startup and rendering
- P2: Fix WaitStable argument — 1 nanosecond → 1 second
- P2: Replace MustPage/MustClose with error-returning Page/Close APIs
  to avoid panics on recoverable browser failures
@rokuosan

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f49a05bef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/ogimage/renderer.go Outdated
- Change page.Screenshot(true, ...) to page.Screenshot(false, ...)
  to preserve the explicit 1200x630 clip dimensions instead of
  expanding to full-page mode when content overflows.
@rokuosan

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 35ee555007

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/ogimage/renderer.go
…an#158 review)

If browser.Connect() fails after launcher.Launch() succeeds, the
chromium process would leak because Leakless(false) was set. Now
we call l.Kill() on connection failure to clean up the orphaned
process.
@rokuosan

Copy link
Copy Markdown
Owner

@codex review

rokuosanai added a commit to rokuosanai/github-issue-cms that referenced this pull request Jul 28, 2026
…an#158 review)

If browser.Connect() fails after launcher.Launch() succeeds, the
chromium process would leak because Leakless(false) was set. Now
we call l.Kill() on connection failure to clean up the orphaned
process.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 53c4fdefe2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/ogimage/renderer.go Outdated
…an#158 review)

- Store template directory (tmplDir) when using custom templates
- Create page with file:// URL based on template directory so
  relative asset references (images, CSS) resolve correctly
- Embedded template continues to use about:blank (no assets)
…rokuosan#158)

- Add ctx.Err() check before expensive browser launch
- Add page.Timeout(30s) so WaitStable/Screenshot cannot hang forever
- Change Leakless(false) → Leakless(true) to prevent zombie Chromium processes
- Fix file:// URL to file:/// (three slashes) for correct absolute path resolution
@rokuosan

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d676eef39

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/ogimage/renderer.go Outdated
- Replace raw string concatenation with url.URL to properly escape
  special characters (#, ?) in template directory paths
- Ensures correct base URL for relative asset resolution even with
  unusual directory names
@rokuosan

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: cfa601362b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@rokuosan
rokuosan merged commit 2d9c9e9 into rokuosan:main Jul 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create OGP image rendering pkg

2 participants