Astral.Route.File (Astral v0.1.2)

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.

Match a concrete path and return string-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: [String.t()],
  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.

match(route, path)

@spec match(t(), String.t()) :: {:ok, map()} | :error

Match a concrete path and return string-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.