feat: integrate OGP image generation into generate command (--with-ogimage) - #160
feat: integrate OGP image generation into generate command (--with-ogimage)#160rokuosanai wants to merge 24 commits into
Conversation
- Add ParseArticleFromMarkdown to core package for reading Hugo-compatible markdown files with YAML frontmatter back into core.Article - Add 'ogimage' subcommand to CLI with -f/--file and -t/--template flags - Convert Article to OGPData and render via pkg/ogimage - Output ogp.jpeg into the configured image output directory - Register ogimage command in root CLI Closes rokuosan#154
- Add --with-ogimage flag to generate subcommand (opt-in) - Add OnArticleSaved callback hook to ArticleGenerator for post-processing - When --with-ogimage is set, OGP images are generated alongside each article - OGP images saved as ogp.jpeg in the article's output directory - Preserves existing behavior when flag is not set Closes rokuosan#155
…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.
…uosan#159) - articleToOGPData: return zero-value OGPData when article is nil - resolveOGPOutputPath: return error when article is nil or Output config missing - Add filepath.Clean for path safety
…adversarial review) CRITICAL: Previously all articles saved ogp.jpeg to the same directory, causing each article to overwrite the previous one's OGP image. Now uses article.Key as a subdirectory for per-article isolation. Also: - Add nil guards in generateOGPForArticle and resolveOGPArticlePath - Add context cancellation check before expensive render - Add filepath.Clean for path safety - Add tests for new path resolution and nil cases
…dit rokuosan#159) - Normalize Windows CRLF line endings to LF - Handle closing frontmatter delimiter at EOF (--- without trailing newline) - Add frontmatter prefix validation before parsing
…audit rokuosan#160) - Track ogpOK/ogpFail counters to show accurate OGP image generation stats - Previously errors were silently swallowed — now user sees how many OGP images succeeded/failed - Remove unused strconv import
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b89184e2d8
ℹ️ 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#160 review) P1: resolveOGPArticlePath now checks the article filename pattern. For page bundles (index.md), OGP goes alongside in the same directory. For flat layouts, uses article Key as subdirectory to prevent overwrites. This matches the actual file layout used by FileSystemArticleRepository. P2: Apply frontmatter overrides before converting to OGPData so the OGP image matches the rendered markdown, not raw GitHub metadata. Export ApplyFrontMatterOverrides from core package for reuse.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4fe446677a
ℹ️ 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".
…eview) - Flat layout: save OGP as adjacent file <name>.ogp.jpeg next to <name>.md instead of orphaned <key>/ogp.jpeg subdirectory (P1) - Log hook failures and failure summary at Error level so they're visible at default verbosity (P1) - Pass frontmatter-overridden article to path resolver so OGP lands in the same directory as the markdown (P2)
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1e3d441eb
ℹ️ 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".
| if err := g.onArticleSaved(article); err != nil { | ||
| // Log at Error level: the CLI's default verbosity filters | ||
| // out Warn, which would make hook failures (e.g. OGP image | ||
| // generation) completely invisible in a normal run. | ||
| g.logger.Error("Post-save hook failed for article", "issue", issue.GetNumber(), "error", err) |
There was a problem hiding this comment.
Propagate cancellation from the final post-save hook
When the context is cancelled while the final article's OGP image is rendering—for example, the user presses Ctrl-C—Renderer.Render returns a cancellation error, but this block only logs and discards it. Because there is no subsequent loop iteration to execute the ctx.Err() check, Generate returns success and the CLI exits with status 0 despite the interrupted image generation; check and return ctx.Err() after invoking the hook.
Useful? React with 👍 / 👎.
…review) - Only strip known markdown extensions (.md/.markdown) before appending .ogp.jpeg; other extensions (e.g. .post, .txt) now get the suffix appended to the full filename so the image always stays adjacent - Add test cases for .post and .markdown filenames
Summary
Implements milestone 3 of #21 — integrates OGP image generation into the
generatecommand via an opt-in--with-ogimageflag.Changes
pkg/core/generator.go— AddOnArticleSavedcallback hook toArticleGeneratorfor post-processing after each article save. The callback is non-blocking — errors are logged as warnings and processing continues.cmd/cli/subcommand/generate.go— Add--with-ogimageboolean flag. When set:ogimage.Rendererand registers it as theOnArticleSavedcallbackogp.jpegin the article's output directorycmd/cli/cli_test.go— Updated to verifyogimagesubcommand registration--with-ogimageflag existence, CLI flag parsingDepends on
Usage
Closes #155
Closes #21