Repository navigation
feat: clickable links and preview cards for links in commits - #73
Merged
Merged
Conversation
Links in a commit's body become clickable, and the first one gets an Open Graph preview under the commit. Replies get them too. Bare domains like nativephp.com count as links, as long as the TLD is on an allowlist that skips file-extension TLDs such as .sh, .md and .rs. Previews live in a link_previews table shared by every commit that links to the same URL. A queued job fetches the page with SSRF guards: public addresses only, the connection pinned to the checked address, redirects followed by hand and re-checked, a 5 second timeout and a 1 MB cap.
simonhamp
force-pushed
the
feat/link-previews
branch
from
October 15, 2026 15:53
1b4a2aa to
9a97019
Compare
This was referenced Oct 16, 2026
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.
Links in a commit's body are now clickable, and the first link gets a small preview card under the commit with the site name, title, description and thumbnail from the page's Open Graph tags. Replies get them too.
On a phone
The card is a hairline-bordered row with no shadow, so commits are still rows and not cards. The text stays the main thing.
How this relates to #36
#36 does something similar for GitHub only. It recognises GitHub references, including short forms like
laravel/framework#1, and shows live details from the GitHub API, like issue state and stars. This PR is more generic. It works for any site that has Open Graph tags (YouTube, docs sites, blogs, GitHub too) and doesn't depend on any one API.If both land they overlap on full GitHub URLs. The simple fix would be to skip the generic preview when #36 already has a card for the link. Happy to do that here or in a follow-up, whichever order they go in.
Also, #57 and #69 call their feature "link previews" too, but that's the other direction: the cards devnull serves when its own links are shared elsewhere. This one shows cards for other sites inside devnull. Nothing collides in the code, but it's worth knowing the name now means two things.
What counts as a link
http://orhttps://.nativephp.comorgithub.com/nunomaduro/devnull.com. They gethttps://added.Bare domains only match a list of 92 common TLDs, because lots of file extensions are real TLDs. So
deploy.sh,README.md,main.rs,Makefile.in,Node.jsandapp.phpstay plain text. A few TLDs that read like code are left out too (user.id,app.run()). Emails and @Handles don't match, a domain followed by(doesn't match (array.at(-1)), and the TLD has to be all lowercase or all uppercase, so a missing space inFixed the bug.It worksdoesn't turn into a link.The PHP side (
FindFirstUrl) and the React side (linkified-text.tsx) follow the same rules, and each points at the other.How it works
CreateCommitfinds the first link in the body. Each URL gets one row in a newlink_previewstable, shared by every commit that links to it, so a page is only fetched once. Commits point at it with a nullablelink_preview_id.UnfurlLink), so posting stays fast. The card shows up once the job has run.composer devalready runs a queue listener, but production needs a worker.Fetching user-supplied URLs
The server fetches whatever people link to, so
FetchLinkPreviewis careful about where it connects:referrerPolicy="no-referrer".Things to look at
PRODUCT.mdlists images and media as "not now". The thumbnails come close to that line. If that's a problem, dropping the image and keeping the text card is a small change.HTTP_PROXY/HTTPS_PROXY, curl goes through the proxy and the IP pin no longer applies.Testing
All gates pass locally: Pest (589 tests) at 100% coverage, type coverage, PHPStan, Rector, Pint, oxlint and tsc. The tests use
Http::fake()and a fake DNS resolver, so nothing touches the network. I also ran the fetch by hand against GitHub, YouTube (over 1 MB, so the cap kicks in), laravel.com and an http to https redirect, and checked that the metadata address and a redirect to 127.0.0.1 were refused.