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
|
|
|
|
|
|
|
|
def in_config?(%Config{} = cfg, path) do
|
|
|
|
Enum.any?([cfg.pages_dir, cfg.posts_dir], &String.starts_with?(path, &1)) and
|
|
|
|
Path.extname(path) == ".md"
|
|
|
|
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
|