Skip to content

og images for docs#861

Merged
Jordy-Baby merged 1 commit intomainfrom
nb/og-meta-images
Apr 13, 2026
Merged

og images for docs#861
Jordy-Baby merged 1 commit intomainfrom
nb/og-meta-images

Conversation

@nikbhintade
Copy link
Copy Markdown
Member

@nikbhintade nikbhintade commented Apr 10, 2026

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.json file.

Build process improvements:

  • Added sharp as a new dependency to handle image processing for OG image generation.
  • Updated the prebuild script to include running generate-og-images.js, ensuring OG images are generated automatically before building.
  • Added new scripts: generate-og-images for generating OG images and preview-og for previewing them.

Summary by CodeRabbit

  • New Features

    • Added automatic Open Graph image generation for documentation pages during the build process, enhancing social media sharing previews.
    • Added preview tool to view generated OG images before deployment.
  • Chores

    • Added image processing library as a development dependency.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
envio-docs Ready Ready Preview, Comment Apr 10, 2026 6:02am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

A 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

Cohort / File(s) Summary
Build Configuration
package.json
Added generate-og-images and preview-og npm scripts; updated prebuild to run node ./scripts/generate-og-images.js; added sharp ^0.34.5 as a devDependency.
OG Image Generation
scripts/generate-og-images.js
New 445-line Node.js script that recursively processes doc files, extracts YAML frontmatter (title, description, section), renders SVG templates with embedded branding and formatted text, converts to PNG via sharp, and updates source file frontmatter with image URLs. Supports --force, --dry-run, and --preview modes with error handling and progress logging.

Sequence Diagram

sequenceDiagram
    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)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop-hop, we generate!
SVG to PNG, don't be late!
Sharp encodes our Envio pride,
With titles and descriptions wide,
Social media glows so bright!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'og images for docs' directly and concisely summarizes the main change: adding OG image generation functionality for documentation files.
Docstring Coverage ✅ Passed Docstring coverage is 81.25% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nb/og-meta-images

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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., sharp import 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ce1f20 and 45b0432.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • package.json
  • scripts/generate-og-images.js

Comment on lines +326 to +329
/** Convert output path to static-relative URL for frontmatter */
function toStaticUrl(outputPath) {
return "/" + path.relative(STATIC_DIR, outputPath);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
/** 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.

@nikbhintade nikbhintade requested a review from Jordy-Baby April 13, 2026 12:44
@Jordy-Baby Jordy-Baby merged commit 9408f88 into main Apr 13, 2026
3 checks passed
@Jordy-Baby Jordy-Baby deleted the nb/og-meta-images branch April 13, 2026 12:49
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.

2 participants