plugins

BareProxy Link Previews Plugin: Open Graph Cards for Pages That Don't Have Them

Status: planned, number 9 of 21 in BareProxy’s build order. The plugins are built easiest first, and this one is about a day of coding: tags added to the head of HTML pages. It comes after the Rate limiting and basic WAF plugin. This post describes what it will do, and it will be updated as it is built.

Paste a link into Slack, WhatsApp, LinkedIn, X or iMessage, and a fetcher comes to read the page’s Open Graph tags: a title, a description and an image for the preview card. A page without them shows up as a bare URL, or with whatever text the fetcher grabbed first, often a cookie notice. Plenty of pages lack them: old pages, app screens, documentation, files a CMS never touched.

What It Will Do

  • Fill in what’s missing. When a preview fetcher asks for an HTML page without Open Graph tags, the plugin adds them to the page’s <head>: the page’s title, its first real paragraph as the description, and its first large image, or a default image from the config.
  • Leave good pages alone. Pages that already have their tags pass through untouched.
  • Only for fetchers. Preview bots are recognized by user agent, and visitors’ pages are never changed. The tags describe the same page a visitor sees, so a preview never promises something the page doesn’t have.
  • Rules per path. A section can get a fixed image and description from the plugin’s config, such as one card for all of /docs/.

A config will look something like this:

plugin previews /etc/bareproxy/plugins/link-previews.wasm
  config /etc/bareproxy/plugins/previews.json
  body response

site example.com
  use previews
  route /* -> files /var/www/example/public

Where It Fits

Link previews and RenderCache solve neighboring problems. RenderCache gives a fetcher a whole rendered page when the page is built by JavaScript. Link previews make sure a plain HTML page tells the fetcher what it is. A JavaScript app may want both; a static site needs only this one.

Each page it changes carries a note in the request’s record, with the tags it added.

The whole program is on the plugins page.