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 19:52:57 -05:00
|
|
|
field :images_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 19:52:57 -05:00
|
|
|
images_dir: Path.join(priv, "site/images"),
|
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
|