Replace Twitter Embeds with Semantic HTML
I logged into Twitter using a fresh account last week. No followers, no preferences set. The default experience was an unending slurry of racism and porn. I don't care to use Twitter any more. Whatever good that was there is now drowned in a cess-pit of violent filth.
I still have a lot of Tweets embedded on this blog. Using WordPress, it was easy to paste in a link and have it converted to an embed. But I don't want to direct people to a dangerous site.
So here's a somewhat automated way to replace embedded Tweets with good-looking and semantic HTML. You no longer need to worry about Twitter tracking people if they visit your site. It in-lines all images and avatars so there's no data leakage. Links go direct rather than through the obnoxious t.co service. The HTML is semantic, short, and accessible.
The simple Python code is available on GitHub - feedback welcome!
Demos
Here are some examples. You'll see all the links work - to external sites, hashtags, or mentions. Media is loaded, emoji work, alt text is included where available, and the CSS is roughly right. The number of likes and replies is shown - but the number of retweets isn't always available in the embed API. The number of quotes and bookmarks aren't available.
Polls
Embedded Images
Quote Tweets
Replies
Videos
The poster of the video is embedded - the actual MP4 is still loaded off Twitter's site.
Get The Code
The simple Python code is available on GitHub - feedback welcome!
Andy Mabbett says:
I'm amused to see that links go to twitter.com, not x.com
@edent says:
x.com? Never heard of it mate!
Erik says:
It's a pretty good videogame series
Simon Greenwood said on gotosocial.grnwds.uk:
@Edent With regard to the algorithmic quality, my wife has very few connections on Facebook and only really uses it to read my daughter's school year message group, and if she looks at her FB feed, it's also full of appalling material, which makes me wonder about the way that the mechanism handles low information input, but not enough to want to dive into various trenches to examine it.
bsky.app said on bsky.app:
@edent.tel You can avoid syndication API call retries, necessary because of random guessing the token, by implementing the following token calculation algo: github.com/vercel/react...
More comments on Mastodon.