downforacross / downforacross.com

Web frontend for downforacross.com -- continuation of stevenhao/crosswordsio
https://downforacrosscom.downforacross1.now.sh
MIT License
220 stars 92 forks source link

Implement link previews #284

Closed shintyl closed 10 months ago

shintyl commented 10 months ago

This PR implements a feature that generates link previews (also known as "embeds") for DFAC game URLs (e.g. https://downforacross.com/beta/game/1234567-joct) sent in platforms such as Discord and Slack. These previews are generated by "link unfurling" crawlers on these platforms that visit the URLs posted in sent messages and search for certain tags.

Using Vercel Middleware, requests can be intercepted before the response is served, and if the request URL is a game URL, and if user-agent string is suggestive of a crawler, the crawler can be redirected while human users are unaffected. Crawlers are redirected to an API endpoint which returns a barebones HTML document containing Open Graph Protocol tags (for that specific game), whose content populates the link preview.

Here's what the link previews look like in Discord and Slack (ignore the URLs):

image image

Simpler approaches, like mutating the DOM in the client-side code to include the tags, unfortunately don't work because none of these crawlers actually seem to execute JavaScript, and only see index.html's initial state. Another approach like moving to server-side rendering would probably take a lot of work.

Note that link previews for the Vercel preview deployment won't be generated because I don't think API changes are reflected until merge.

vercel[bot] commented 10 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
downforacross.com ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 10, 2023 6:13pm
stevenhao commented 10 months ago

This looks really good! Ready to merge whenever; if it's not much work to support link previews on fb messenger then we can try to get that included first.

stevenhao commented 10 months ago

shipped!!

image