Configuration handling for Sayfa sites.
Provides functions to read site configuration with sensible defaults. Configuration is resolved from three layers (lowest to highest priority):
- Built-in defaults
- Application environment (
config :sayfa, :site, ...) - Runtime options passed to
resolve/1
Examples
# Get a single config value
Sayfa.Config.get(:title)
#=> "My Site"
# Get with a custom default
Sayfa.Config.get(:missing_key, "fallback")
#=> "fallback"
# Resolve full config map
config = Sayfa.Config.resolve(content_dir: "custom/content")
config.content_dir
#=> "custom/content"
Summary
Functions
Returns the absolute path to a file within the default theme.
Returns the built-in default configuration map.
Gets a single configuration value.
Resolves a complete configuration map.
Returns the path to the layouts directory for the given config.
Functions
Returns the absolute path to a file within the default theme.
Uses :code.priv_dir/1 to locate Sayfa's priv/ directory.
Examples
iex> path = Sayfa.Config.default_theme_path("layouts")
iex> String.ends_with?(path, "priv/default_theme/layouts")
true
@spec defaults() :: map()
Returns the built-in default configuration map.
Examples
iex> defaults = Sayfa.Config.defaults()
iex> defaults.title
"My Site"
Gets a single configuration value.
Looks up the key in application environment, falling back to built-in defaults.
Examples
iex> Sayfa.Config.get(:title)
"My Site"
iex> Sayfa.Config.get(:nonexistent, "default")
"default"
Resolves a complete configuration map.
Merges built-in defaults, application environment, and runtime options (in that priority order) into a single map.
Examples
iex> config = Sayfa.Config.resolve(title: "Custom Site")
iex> config.title
"Custom Site"
iex> config = Sayfa.Config.resolve([])
iex> config.output_dir
"dist"
Returns the path to the layouts directory for the given config.
For the default theme, returns the path inside Sayfa's priv/ directory.
For custom themes, returns themes/<name>/layouts/ relative to the site root.
Examples
iex> config = %{theme: "default"}
iex> path = Sayfa.Config.theme_layouts_dir(config)
iex> String.ends_with?(path, "default_theme/layouts")
true