- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.6k
feat: Implement Open Graph image resolution logic #15335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Added a helper function to resolve Open Graph image URLs based on various conditions, including manual overrides and fallback mechanisms. - Integrated the new function into the metadata generation process to prioritize custom images, the first image from content, or a default image. - Introduced a new remark plugin to extract the first image from markdown content for use in Open Graph metadata. - Updated frontmatter type definitions to include an optional `og_image` field for custom Open Graph images.
| The latest updates on your projects. Learn more about Vercel for GitHub. 
 | 
…age field - Moved the firstImage property to the end of the SlugFile type definition for better organization. - Updated the remarkExtractFirstImage function to return undefined when no image is found, improving clarity in the image extraction logic.
| Bundle ReportChanges will increase total bundle size by 126.24kB (0.54%) ⬆️. This is within the configured threshold ✅ Detailed changes
 Affected Assets, Files, and Routes:view changes for bundle: sentry-docs-server-cjsAssets Changed:
 Files in  
 App Routes Affected:
 view changes for bundle: sentry-docs-client-array-pushAssets Changed:
 | 
- Added directory existence check for mdx-images to prevent errors when accessing images. - Improved error handling and logging for image resolution failures. - Updated asset caching logic to handle Vercel deployment scenarios, ensuring images are correctly managed in read-only environments. - Enhanced overall robustness of the image resolution process by returning null when images are not found, allowing for fallback to default images.
- Refactored the `resolveOgImageUrl` function to remove asynchronous operations, improving performance and clarity. - Updated the logic to handle image paths more efficiently, ensuring that fallback mechanisms are in place when images are not found. - Enhanced the integration of the image resolution function within the metadata generation process, streamlining the handling of custom and default images.
- Changed the way metafile is accessed in the getFileBySlug function to ensure type safety by casting the result to 'any'. - Improved clarity by defining the metafile structure explicitly, enhancing maintainability and reducing potential runtime errors.
…eBySlug function - Enhanced the logic to detect Vercel and AWS Lambda environments, ensuring proper usage of the /tmp directory to avoid read-only file system errors. - Updated comments for clarity regarding the deployment scenarios and the handling of output directories.
and add a script to copy images into the public folder
- Updated the logic to always use the public/mdx-images directory during build, removing the conditional checks for Vercel and AWS Lambda environments. - Improved comments for clarity regarding directory creation and asset copying, ensuring that images are assumed to exist from build time. - Streamlined cache checking logic by removing unnecessary runtime checks, enhancing maintainability.
- Introduced a README file in the public/og-images directory to document the generation and usage of Open Graph images. - Updated the addOgImageToFile function to always copy the source image, ensuring that images are regenerated on each build, even if frontmatter already exists. - Enhanced error handling to track and report any image copy errors during the generation process.
- Added 'public/og-images/**/*' to the outputFileTracingExcludes for both '/platform-redirect' and sitemap.xml paths, ensuring proper handling of Open Graph images during the build process.
|  | ||
| // Simple regex to find markdown images  | ||
| const IMAGE_REGEX = /!\[([^\]]*)\]\(([^)]+)\)/; | ||
|  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Regex Fails with Parentheses in Image Paths
The IMAGE_REGEX in add-og-images.ts uses [^)]+ to capture image paths, which stops at the first closing parenthesis. This causes image paths containing parentheses to be truncated, preventing the script from finding and copying the correct image file.
og_imagefield for custom Open Graph images.