inlay

Render embedded previews for social media links as Lustre HTML elements.

Use detect to parse a URL into an Embed, render to turn it into HTML, or embed to do both in one step. All functions have _with variants that accept a custom Config.

Example

case inlay.embed("https://www.youtube.com/watch?v=dQw4w9WgXcQ") {
  Some(element) -> element
  None -> html.text("Not an embeddable link")
}

Configuration

let config =
  inlay.new()
  |> inlay.youtube(inlay.youtube_config())
  |> inlay.mastodon(inlay.mastodon_config(["mastodon.social"]))

Types

Provider configuration. Create with default_config() or new(), then customize with builder functions like youtube(), no_twitter().

pub type Config =
  embed.Config

A detected embeddable link with provider-specific data. Match on variants to inspect or handle providers individually.

pub type Embed =
  embed.Embed
pub type TedConfig =
  embed.TedConfig

Values

pub fn a_component(
  fallback: fn(
    String,
    option.Option(String),
    List(element.Element(msg)),
  ) -> element.Element(msg),
) -> fn(String, option.Option(String), List(element.Element(msg))) -> element.Element(
  msg,
)

Create an anchor component that renders embeds for recognized URLs and delegates to fallback for unrecognized ones. Uses the default configuration.

pub fn a_component_default() -> fn(
  String,
  option.Option(String),
  List(element.Element(msg)),
) -> element.Element(msg)

Create an anchor component using the default configuration and a standard <a> tag fallback.

pub fn a_component_with(
  config: embed.Config,
  fallback: fn(
    String,
    option.Option(String),
    List(element.Element(msg)),
  ) -> element.Element(msg),
) -> fn(String, option.Option(String), List(element.Element(msg))) -> element.Element(
  msg,
)

Create an anchor component with a custom configuration.

pub fn apple_music(
  config: embed.Config,
  apple_music_config: embed.AppleMusicConfig,
) -> embed.Config

Enable Apple Music embeds with the given configuration.

pub fn apple_music_config() -> embed.AppleMusicConfig

Create a default Apple Music configuration.

pub fn bluesky(
  config: embed.Config,
  bluesky_config: embed.BlueskyConfig,
) -> embed.Config

Enable Bluesky embeds with the given configuration.

pub fn bluesky_config() -> embed.BlueskyConfig

Create a default Bluesky configuration with no handle resolver.

pub fn bluesky_resolver(
  config: embed.BlueskyConfig,
  resolve: fn(String) -> Result(String, Nil),
) -> embed.BlueskyConfig

Set a function that resolves a Bluesky handle (e.g. "user.bsky.social") to a DID. When provided, embeds render with richer Bluesky markup.

pub fn default_config() -> embed.Config

Create a configuration with commonly used providers enabled.

Enabled: YouTube, Vimeo, Spotify, Twitter/X, TikTok, Bluesky, Instagram, OpenStreetMap, TED, SoundCloud, Apple Music.

Disabled (require explicit setup): Twitch, Mastodon, Pixelfed.

pub fn detect(url: String) -> option.Option(embed.Embed)

Detect an embeddable link from a URL using the default configuration.

pub fn detect_with(
  url: String,
  config: embed.Config,
) -> option.Option(embed.Embed)

Detect an embeddable link from a URL using a custom configuration.

pub fn embed(url: String) -> option.Option(element.Element(msg))

Detect and render in one step using the default configuration.

pub fn embed_with(
  url: String,
  config: embed.Config,
) -> option.Option(element.Element(msg))

Detect and render in one step using a custom configuration.

pub fn instagram(config: embed.Config) -> embed.Config

Enable Instagram embeds.

pub fn mastodon(
  config: embed.Config,
  mastodon_config: embed.MastodonConfig,
) -> embed.Config

Enable Mastodon embeds with the given configuration.

pub fn mastodon_config(
  servers: List(String),
) -> embed.MastodonConfig

Create a Mastodon configuration. Only posts from the listed servers will be detected.

pub fn new() -> embed.Config

Create a configuration with all providers disabled. Enable providers selectively with the builder functions.

pub fn no_apple_music(config: embed.Config) -> embed.Config

Disable Apple Music embeds.

pub fn no_bluesky(config: embed.Config) -> embed.Config

Disable Bluesky embeds.

pub fn no_instagram(config: embed.Config) -> embed.Config

Disable Instagram embeds.

pub fn no_mastodon(config: embed.Config) -> embed.Config

Disable Mastodon embeds.

pub fn no_openstreetmap(config: embed.Config) -> embed.Config

Disable OpenStreetMap embeds.

pub fn no_pixelfed(config: embed.Config) -> embed.Config

Disable Pixelfed embeds.

pub fn no_soundcloud(config: embed.Config) -> embed.Config

Disable SoundCloud embeds.

pub fn no_spotify(config: embed.Config) -> embed.Config

Disable Spotify embeds.

pub fn no_ted(config: embed.Config) -> embed.Config

Disable TED talk embeds.

pub fn no_tiktok(config: embed.Config) -> embed.Config

Disable TikTok embeds.

pub fn no_twitch(config: embed.Config) -> embed.Config

Disable Twitch embeds.

pub fn no_twitter(config: embed.Config) -> embed.Config

Disable Twitter/X embeds.

pub fn no_vimeo(config: embed.Config) -> embed.Config

Disable Vimeo embeds.

pub fn no_youtube(config: embed.Config) -> embed.Config

Disable YouTube embeds.

pub fn openstreetmap(
  config: embed.Config,
  osm_config: embed.OpenStreetMapConfig,
) -> embed.Config

Enable OpenStreetMap embeds with the given configuration.

pub fn openstreetmap_config() -> embed.OpenStreetMapConfig

Create a default OpenStreetMap configuration.

pub fn pixelfed(
  config: embed.Config,
  pixelfed_config: embed.PixelfedConfig,
) -> embed.Config

Enable Pixelfed embeds with the given configuration.

pub fn pixelfed_compact() -> embed.PixelfedLayout

Pixelfed embed layout that shows a compact view of the post.

pub fn pixelfed_config(
  servers: List(String),
  layout: embed.PixelfedLayout,
) -> embed.PixelfedConfig

Create a Pixelfed configuration. Only posts from the listed servers will be detected.

pub fn pixelfed_full(
  caption caption: Bool,
  likes likes: Bool,
) -> embed.PixelfedLayout

Pixelfed embed layout that shows the post with optional caption and likes.

pub fn render(embed: embed.Embed) -> element.Element(msg)

Render a detected embed as HTML using the default configuration.

pub fn render_with(
  embed: embed.Embed,
  config: embed.Config,
) -> element.Element(msg)

Render a detected embed as HTML using a custom configuration.

pub fn soundcloud(
  config: embed.Config,
  soundcloud_config: embed.SoundCloudConfig,
) -> embed.Config

Enable SoundCloud embeds with the given configuration.

pub fn soundcloud_config() -> embed.SoundCloudConfig

Create a default SoundCloud configuration.

pub fn spotify(
  config: embed.Config,
  spotify_config: embed.SpotifyConfig,
) -> embed.Config

Enable Spotify embeds with the given configuration.

pub fn spotify_config() -> embed.SpotifyConfig

Create a default Spotify configuration.

pub fn ted(
  config: embed.Config,
  ted_config: embed.TedConfig,
) -> embed.Config

Enable TED talk embeds with the given configuration.

pub fn ted_config() -> embed.TedConfig

Create a default TED configuration.

pub fn tiktok(config: embed.Config) -> embed.Config

Enable TikTok embeds.

pub fn twitch(
  config: embed.Config,
  twitch_config: embed.TwitchConfig,
) -> embed.Config

Enable Twitch embeds with the given configuration.

pub fn twitch_config(parent: String) -> embed.TwitchConfig

Create a Twitch configuration. The parent domain is required by Twitch’s embed API.

pub fn twitter(config: embed.Config) -> embed.Config

Enable Twitter/X embeds.

pub fn vimeo(
  config: embed.Config,
  vimeo_config: embed.VimeoConfig,
) -> embed.Config

Enable Vimeo embeds with the given configuration.

pub fn vimeo_config() -> embed.VimeoConfig

Create a default Vimeo configuration with Do Not Track enabled.

pub fn vimeo_dnt(
  config: embed.VimeoConfig,
  dnt: Bool,
) -> embed.VimeoConfig

Set whether Vimeo embeds include the Do Not Track flag. Enabled by default.

pub fn youtube(
  config: embed.Config,
  youtube_config: embed.YoutubeConfig,
) -> embed.Config

Enable YouTube embeds with the given configuration.

pub fn youtube_config() -> embed.YoutubeConfig

Create a default YouTube configuration with privacy-enhanced mode enabled.

pub fn youtube_no_cookie(
  config: embed.YoutubeConfig,
  no_cookie: Bool,
) -> embed.YoutubeConfig

Set whether YouTube embeds use the privacy-enhanced youtube-nocookie.com domain. Enabled by default.

Search Document