fix: serve OG image as static public/og-image.png for LinkedIn#55
Merged
Conversation
The previous /og-image controller route was rejected by LinkedIn's Post Inspector even after the MiniMagick v5 fix: Image No image found Alternate values we considered (empty) Two compounding causes: 1. Rails' send_file returned HEAD with content-length: 0 (only GET set the body length correctly). LinkedIn's image validator HEADs first and treats a zero-length response as "image missing." 2. The URL had no file extension. LinkedIn's parser favours URLs that end in a recognized image extension when picking the OG image. Pivoting to a real static asset solves both: Thruster sets a correct Content-Length on every method, and the URL is now /og-image.png. The generator now writes directly to public/og-image.png. A small after_initialize hook regenerates it on every boot so the card always reflects the latest achievements.yml (achievements only change at deploy time, which is when the container restarts). Cache check still short-circuits when the existing file is newer than achievements.yml, so dev boot stays fast.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/og-imagestarted returning a real PNG. But LinkedIn's Post Inspector still reportedNo image foundforhttps://rectorspace.com.send_filereturnsHEADwithcontent-length: 0(Rails only writes the body length onGET). LinkedIn HEADs first and treats zero-length as "image missing."public/og-image.pngand let Thruster serve it as a real static asset. Both blockers disappear:Content-Lengthfor HEAD and GET (verified locally:content-length: 51090on both methods)/og-image.pngafter_initializehook inconfig/initializers/og_image_warmup.rb. Cache check short-circuits when the existing file is newer thanachievements.yml, so dev boot isn't slowed down.Test plan
bin/rails runner 'OgImageGenerator.cached_path'writes the 51KB PNG topublic/og-image.pnginstead oftmp/cache/og/curl -I http://localhost:3334/og-image.pngreturns200,content-type: image/png,content-length: 51090curl -X GET -I http://localhost:3334/og-image.pngreturns identical headersbin/rails routes | grep ogreturns nothing (dynamic route removed)curl -I https://rectorspace.com/og-image.pngmatches localhttps://rectorspace.comshows the rendered OG card under "When this link is shared..."Files
app/services/og_image_generator.rb— cache path →public/og-image.pngconfig/initializers/og_image_warmup.rb— regenerate on boot (rescue-guarded)app/views/layouts/application.html.erb—og:image+twitter:image→/og-image.pngconfig/routes.rb— remove dynamicog-imagerouteapp/controllers/og_images_controller.rb— deleted.gitignore— ignore generatedpublic/og-image.png