Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughA new OG image generation workflow is introduced via a Node.js script that creates PNG images for documentation files. The script reads markdown frontmatter, renders SVG templates with project branding, and converts to PNG using sharp. Three npm scripts and a dev dependency are added, with the prebuild step updated to include OG generation. Changes
Sequence DiagramsequenceDiagram
participant User
participant Script as generate-og-images.js
participant FS as File System
participant Parser as YAML Parser
participant SVGEngine as SVG Renderer
participant Sharp as Sharp (Image Conv.)
User->>Script: Run script (--force/--preview)
Script->>FS: Recursively scan docs/ for MD/MDX
FS-->>Script: Return eligible file paths
loop For each file
Script->>FS: Read file content
FS-->>Script: File content + frontmatter
Script->>Parser: Extract title, description, image
Parser-->>Script: Parsed metadata
alt Has existing image & no --force
Script->>Script: Skip file
else Generate image
Script->>SVGEngine: Render SVG template<br/>(title, desc, section, logo)
SVGEngine-->>Script: SVG string
Script->>Sharp: Convert SVG → PNG
Sharp-->>Script: PNG buffer
Script->>FS: Write PNG to static/docs-assets/og/
Script->>FS: Update frontmatter with image URL
end
end
Script-->>User: Log results (generated/skipped/errors)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
scripts/generate-og-images.js (1)
445-445: Add explicit error handling for the main promise.If
main()rejects due to unexpected errors (e.g.,sharpimport failure, missing directories), the promise rejection may produce confusing output. Explicit handling improves debuggability.♻️ Proposed fix
-main(); +main().catch((err) => { + console.error("Fatal error:", err); + process.exit(1); +});🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@scripts/generate-og-images.js` at line 445, The call to main() is unhandled if it rejects; update the invocation of the top-level async function main() to explicitly handle promise rejections by attaching a .catch handler (e.g., main().catch(err => { console.error('Error in main:', err); process.exit(1); })) or replace the call with an immediately-invoked async function that wraps await main() in try/catch and logs the error and exits; reference the main() invocation and ensure the handler logs the error details and exits with a non-zero code for CI-friendly failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@scripts/generate-og-images.js`:
- Around line 326-329: toStaticUrl produces backslashes on Windows because
path.relative returns platform separators; update the toStaticUrl function to
normalize the relative path to URL-safe forward slashes by computing
path.relative(STATIC_DIR, outputPath) and then converting platform backslashes
to '/' (e.g., replace backslashes or split/join using path.sep), finally
prefixing with '/' so the returned URL is always like
'/docs-assets/og/file.png'; reference the toStaticUrl function and
STATIC_DIR/path.relative usage when making the change.
---
Nitpick comments:
In `@scripts/generate-og-images.js`:
- Line 445: The call to main() is unhandled if it rejects; update the invocation
of the top-level async function main() to explicitly handle promise rejections
by attaching a .catch handler (e.g., main().catch(err => { console.error('Error
in main:', err); process.exit(1); })) or replace the call with an
immediately-invoked async function that wraps await main() in try/catch and logs
the error and exits; reference the main() invocation and ensure the handler logs
the error details and exits with a non-zero code for CI-friendly failure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: df47073b-ef18-4a95-92ca-8b62bb68d200
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (2)
package.jsonscripts/generate-og-images.js
| /** Convert output path to static-relative URL for frontmatter */ | ||
| function toStaticUrl(outputPath) { | ||
| return "/" + path.relative(STATIC_DIR, outputPath); | ||
| } |
There was a problem hiding this comment.
Cross-platform path separator issue.
path.relative returns backslashes on Windows, producing invalid URLs like /docs-assets\og\file.png instead of /docs-assets/og/file.png.
🔧 Proposed fix
/** Convert output path to static-relative URL for frontmatter */
function toStaticUrl(outputPath) {
- return "/" + path.relative(STATIC_DIR, outputPath);
+ return "/" + path.relative(STATIC_DIR, outputPath).split(path.sep).join("/");
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** Convert output path to static-relative URL for frontmatter */ | |
| function toStaticUrl(outputPath) { | |
| return "/" + path.relative(STATIC_DIR, outputPath); | |
| } | |
| /** Convert output path to static-relative URL for frontmatter */ | |
| function toStaticUrl(outputPath) { | |
| return "/" + path.relative(STATIC_DIR, outputPath).split(path.sep).join("/"); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@scripts/generate-og-images.js` around lines 326 - 329, toStaticUrl produces
backslashes on Windows because path.relative returns platform separators; update
the toStaticUrl function to normalize the relative path to URL-safe forward
slashes by computing path.relative(STATIC_DIR, outputPath) and then converting
platform backslashes to '/' (e.g., replace backslashes or split/join using
path.sep), finally prefixing with '/' so the returned URL is always like
'/docs-assets/og/file.png'; reference the toStaticUrl function and
STATIC_DIR/path.relative usage when making the change.
This pull request updates the build process and dependencies to support automatic Open Graph (OG) image generation. The main changes include adding a new dependency and updating scripts in the
package.jsonfile.Build process improvements:
sharpas a new dependency to handle image processing for OG image generation.prebuildscript to include runninggenerate-og-images.js, ensuring OG images are generated automatically before building.generate-og-imagesfor generating OG images andpreview-ogfor previewing them.Summary by CodeRabbit
New Features
Chores