Skip to main content

Module embed

Module embed 

Source
Expand description

Embed provider discovery + responsive render.

Naively emitting a pasted URL as <iframe src="{the raw url}"> is broken for the URLs people actually paste: a YouTube watch URL or a Vimeo page URL won’t load in an <iframe> (you need the provider’s embed URL), and an arbitrary URL in an iframe is both broken and a clickjacking surface.

This module recognises the common video providers from a public URL, rewrites it to the embeddable src, and the block template wraps it in a CSS aspect-ratio box so the player stays responsive. Detection is a pure, synchronous URL transformation (no network) so it runs inside the synchronous block-render path (crate::block::BlockRenderCtx carries no pool). Providers are an explicit whitelist; an unrecognised URL renders as a safe link-out rather than an arbitrary iframe.

oEmbed metadata (title / thumbnail fetched from the provider’s oEmbed endpoint) needs outbound HTTP + a cache and is out of scope here — the render path is synchronous, so that belongs in a save-time or prefetch-time resolver, tracked separately.

Adding a provider is a match arm + an id extractor + a test.

Structs§

EmbedTarget
Recognising a public URL: the provider, the embeddable iframe src, and the responsive aspect ratio.

Enums§

Provider
A recognised embed provider. The whitelist — anything not here falls back to a link-out.

Functions§

resolve
Recognise url and return its embeddable target, or None for an unrecognised provider (the caller links out rather than iframing an arbitrary URL).