Behaviour for Astral site plugins.
Plugins participate in site configuration, discovery, page rendering, and
build lifecycle events. All callbacks except name/0 are optional.
Plugins may be configured as modules or {module, opts} tuples. When a
plugin defines a callback with one extra arity, Astral passes tuple opts as
the final argument.
Plugins can opt into Vite/Volt-style ordering with enforce/0 or
enforce/1: :pre plugins run before normal plugins, and :post plugins
run after them.
Summary
Callbacks
Run after a successful static build.
Run before a static build starts.
Transform the normalized site config before discovery/build/dev use.
Return :pre, :post, or nil to control plugin ordering.
Plugin name for identification and error messages.
Transform rendered page HTML.
Render a plugin-owned generated route.
Return generated routes such as feeds, sitemaps, tag pages, or pagination pages.
Transform a discovered site before rendering.
Types
Callbacks
@callback build_done(result :: Astral.BuildResult.t()) :: :ok | {:error, term()}
Run after a successful static build.
@callback build_done(result :: Astral.BuildResult.t(), opts :: keyword()) :: :ok | {:error, term()}
@callback build_start(config :: Astral.Config.t()) :: :ok | {:error, term()}
Run before a static build starts.
@callback build_start(config :: Astral.Config.t(), opts :: keyword()) :: :ok | {:error, term()}
@callback config(config :: Astral.Config.t()) :: Astral.Config.t()
Transform the normalized site config before discovery/build/dev use.
@callback config(config :: Astral.Config.t(), opts :: keyword()) :: Astral.Config.t()
@callback enforce() :: :pre | :post | nil
Return :pre, :post, or nil to control plugin ordering.
@callback enforce(opts :: keyword()) :: :pre | :post | nil
@callback name() :: String.t()
Plugin name for identification and error messages.
@callback render_page( html :: String.t(), page :: Astral.Page.t(), site :: Astral.Site.t() ) :: {:ok, String.t()} | nil
Transform rendered page HTML.
@callback render_page( html :: String.t(), page :: Astral.Page.t(), site :: Astral.Site.t(), opts :: keyword() ) :: {:ok, String.t()} | nil
@callback render_route(route :: Astral.Route.t(), site :: Astral.Site.t()) :: {:ok, route_body()} | {:ok, route_body(), String.t()} | {:ok, route_body(), String.t(), route_headers()} | {:error, term()} | nil
Render a plugin-owned generated route.
@callback render_route( route :: Astral.Route.t(), site :: Astral.Site.t(), opts :: keyword() ) :: {:ok, route_body()} | {:ok, route_body(), String.t()} | {:ok, route_body(), String.t(), route_headers()} | {:error, term()} | nil
@callback routes(site :: Astral.Site.t()) :: [Astral.Route.t()]
Return generated routes such as feeds, sitemaps, tag pages, or pagination pages.
@callback routes(site :: Astral.Site.t(), opts :: keyword()) :: [Astral.Route.t()]
@callback site_discovered(site :: Astral.Site.t()) :: Astral.Site.t()
Transform a discovered site before rendering.
@callback site_discovered(site :: Astral.Site.t(), opts :: keyword()) :: Astral.Site.t()