sloane.sh/lib/sloane_sh/config.ex

36 lines
715 B
Elixir
Raw Normal View History

2024-02-16 22:28:13 -05:00
defmodule SloaneSH.Config do
@moduledoc """
SloaneSH configuration
"""
use TypedStruct
alias __MODULE__
typedstruct do
field :pages_dir, String.t(), enforce: true
field :posts_dir, String.t(), enforce: true
2024-02-24 08:43:08 -05:00
field :output_dir, String.t(), enforce: true
2024-02-16 22:28:13 -05:00
end
def default do
priv = :code.priv_dir(:sloane_sh) |> resolve_link()
%Config{
pages_dir: Path.join(priv, "site/pages"),
posts_dir: Path.join(priv, "site/posts"),
2024-02-24 08:43:08 -05:00
output_dir: Path.join(priv, "output")
2024-02-16 22:28:13 -05:00
}
end
defp resolve_link(path) do
case File.read_link(path) do
{:ok, link} ->
dir = Path.dirname(path)
Path.expand(link, dir)
_ ->
path
end
end
end