Astral.Route.File (Astral v0.2.3)

Copy Markdown View Source

Converts portable file-route names into Astral route patterns.

File routes use Astro-style bracket segments because : and * are awkward in filenames on Windows and in shells:

pages/blog/[slug].astral    -> /blog/:slug
pages/docs/[...path].md     -> /docs/*path

The resulting route patterns keep Astral's Elixir/Phoenix-style :param and *glob syntax at the API boundary.

Summary

Functions

Return true when a relative page path contains bracket route params.

Generate a concrete route path from a dynamic file route path contract.

Match a concrete path and return atom-keyed params for template assigns.

Parse a path relative to the pages directory into a file route.

Return the concrete static route path for a non-dynamic file route.

Types

t()

@type t() :: %Astral.Route.File{
  dynamic?: boolean(),
  params: %{required(String.t()) => atom()},
  pattern: Astral.Route.Pattern.t(),
  source: String.t()
}

Functions

dynamic?(relative)

@spec dynamic?(String.t()) :: boolean()

Return true when a relative page path contains bracket route params.

generate(route, path)

@spec generate(t(), Astral.Route.Path.t()) :: String.t()

Generate a concrete route path from a dynamic file route path contract.

match(route, path)

@spec match(t(), String.t()) ::
  {:ok, %{required(atom()) => String.t() | nil}} | :error

Match a concrete path and return atom-keyed params for template assigns.

parse(relative)

@spec parse(String.t()) :: t()

Parse a path relative to the pages directory into a file route.

static_path(relative)

@spec static_path(String.t() | t()) :: String.t()

Return the concrete static route path for a non-dynamic file route.