sloane.sh/lib/sloane_sh/build.ex

32 lines
848 B
Elixir
Raw Normal View History

2024-02-16 22:28:13 -05:00
defmodule SloaneSH.Build do
require Logger
alias SloaneSH.Context
def run(%Context{} = ctx) do
2024-02-24 13:16:56 -05:00
assets = ctx.posts ++ ctx.pages
File.mkdir_p!(ctx.config.output_dir)
for asset <- assets do
case asset.mod.render(ctx.config, ctx, asset.src, asset.src_contents, asset.attrs) do
{:ok, output_files} ->
for {dest, content} <- output_files do
with :ok <- dest |> Path.dirname() |> File.mkdir_p(),
:ok <- File.write(dest, content) do
Logger.info("Wrote #{inspect(dest)}.")
else
{:error, err} ->
Logger.error("Failed to write #{inspect(dest)}, #{inspect(err)}")
end
end
err ->
Logger.error("Failed to render #{inspect(asset.src)}, #{inspect(err)}")
end
2024-02-16 22:28:13 -05:00
end
2024-02-24 13:53:53 -05:00
:ok
2024-02-16 22:28:13 -05:00
end
end