Behaviour for defining build pipeline hooks.
Hooks allow extending the build pipeline at four stages:
:before_parse— receives aSayfa.Content.Rawstruct before Markdown rendering:after_parse— receives aSayfa.Contentstruct after parsing:before_render— receives aSayfa.Contentstruct before template rendering:after_render— receives a{Sayfa.Content.t(), html_string}tuple after rendering
Hooks are registered via application config:
config :sayfa, :hooks, [MyApp.Hooks.InjectAnalytics]Hooks run sequentially in the order they are registered. If any hook
returns {:error, reason}, the pipeline halts.
Examples
defmodule MyApp.Hooks.InjectAnalytics do
@behaviour Sayfa.Behaviours.Hook
@impl true
def stage, do: :after_render
@impl true
def run({content, html}, _opts) do
{:ok, {content, html <> "<script>/* analytics */</script>"}}
end
end
Summary
Callbacks
Runs the hook on the given content at the configured stage.
The pipeline stage at which this hook runs.