Astral.Image.Remote.Pattern (Astral v0.1.6)

Copy Markdown View Source

A remote image allowlist pattern.

Patterns are declared with URL-shaped strings such as https://images.example.com/** or https://**.amazonaws.com/bucket/**. Hostname wildcards follow Astro's semantics:

  • *.example.com matches one subdomain level.
  • **.example.com matches any subdomain depth.

Pathname wildcards also follow Astro's semantics:

  • /assets/* matches exactly one nested segment.
  • /assets/** matches any nested path below /assets/.

Summary

Functions

Return true when the URL matches the pattern.

Parse a URL-shaped remote allowlist pattern.

Types

t()

@type t() :: %Astral.Image.Remote.Pattern{
  hostname: String.t() | nil,
  pathname: String.t() | nil,
  port: String.t() | nil,
  protocol: String.t() | nil
}

Functions

match?(pattern, uri)

@spec match?(t(), URI.t()) :: boolean()

Return true when the URL matches the pattern.

parse(pattern)

@spec parse(String.t()) :: {:ok, t()} | {:error, term()}

Parse a URL-shaped remote allowlist pattern.