Yesterday I posted that I’d resolved my new microblog POSSE1 posts from generating link previews on Mastodon and Bluesky. Today, I want to briefly run through how I managed that.
Similar to the solution in Stopping Mastodon From Fetching Metadata for My Notes, I wanted to include links to the original microblog notes when syndicating to Mastodon and Bluesky. Unfortunately, if a link is present and has Open Graph metadata tags then a redundant link preview is generated, which takes up a bunch of vertical space in your feed and provides no value in this case. ’s
Hearthside is written in Rails, so Robb’s solution didn’t directly translate, but the general solution here is pretty similar in that I check the request’s User-Agent header against a list of Fediverse and Bluesky substrings and return an empty response if those match.
scope constraints: ->(request) {
/(Akkoma|
B(lue)?sky
Bridgy|
Firefish|
Frendica|
Mastodon|
Misskey|
Pleorma|
gotosocial
)/ix =~ request.user_agent
} do
match '/micro/:id', via: [:get, :head], to: ->(_) {
[
200,
{ 'Content-Type' => 'text/html' },
['<!DOCTYPE html><title>.</title>'],
]
}
end
resources :notes, path: '/micro', only: [:show, :index]
Advanced Rails Routing Constraints that despite being published about a decade ago is still perfectly relevant to my needs. It pointed out the wrote a post on scope constraints: ->(request) { ... }
block that I was able to use above to match requests to my NotesController
that return true from the Proc
provided.
The list of user agent substrings is courtesy of Adam Newbold via Robb’s post.
Rails will take a Proc
that returns an Array of response code, headers, and body as the :to
argument for match
. I use that to generate an inline response with a minimally viable HTML document to these responses so it doesn’t even hit the rest of the Rails stack.
-
Publish on your own Site, Syndicate Elsewhere, as opposed to PESOS, Publish Elsewhere, Syndicate to your Own Site ↩