Bluesky.Facet (broadcast v0.2.0)

Helper module for interfacing with the Bluesky Facet API: https://docs.bsky.app/docs/advanced-guides/post-richtext

Summary

Functions

Extracts both link and hashtag facets from the given text.

Extracts hashtag facets from the given text.

Extracts link facets from the given text.

Functions

facets(text)

Extracts both link and hashtag facets from the given text.

Scans the input text for URLs and hashtags, returning their positions along with associated features.

Parameters

  • text: A string containing the text to scan for links and hashtags.

Examples

iex> Bluesky.Facet.facets("Visit us at https://example.com, and use #elixir")
[
  %{
    "index" => %{"byteStart" => 12, "byteEnd" => 31},
    "features" => [%{"$type" => "app.bsky.richtext.facet#link", "uri" => "https://example.com"}]
  },
  %{
    "index" => %{"byteStart" => 41, "byteEnd" => 48},
    "features" => [%{"$type" => "app.bsky.richtext.facet#tag", "tag" => "elixir"}]
  }
]

hashtags(text)

Extracts hashtag facets from the given text.

Scans the input text for hashtags and returns their positions along with associated features. Hashtags are captured from the '#' until the next whitespace character and are only included if they consist entirely of alphanumeric characters and underscores.

Parameters

  • text: A string containing the text to scan for hashtags.

Examples

iex> Bluesky.Facet.hashtags("Check out the #elixir programming language!")
[
  %{
    "index" => %{"byteStart" => 14, "byteEnd" => 21},
    "features" => [%{"$type" => "app.bsky.richtext.facet#tag", "tag" => "elixir"}]
  }
]

iex> Bluesky.Facet.hashtags("Invalid hashtag: #$invalid")
[]

links(text)

Extracts link facets from the given text.

Scans the input text for URLs and returns their positions along with associated features.

Parameters

  • text: A string containing the text to scan for links.

Examples

iex> Bluesky.Facet.links("Visit us at https://example.com.")
[
  %{
    "index" => %{"byteStart" => 12, "byteEnd" => 31},
    "features" => [%{"$type" => "app.bsky.richtext.facet#link", "uri" => "https://example.com"}]
  }
]

iex> Bluesky.Facet.links("Check out https://sub.example.com/path, it's cool!")
[
  %{
    "index" => %{"byteStart" => 10, "byteEnd" => 38},
    "features" => [%{"$type" => "app.bsky.richtext.facet#link", "uri" => "https://sub.example.com/path"}]
  }
]