2024-02-16 22:28:13 -05:00
|
|
|
defmodule SloaneSH.Write do
|
|
|
|
def page(ctx, src, data) do
|
|
|
|
path = md_to_html(src)
|
|
|
|
|
|
|
|
write(ctx, path, data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def post(ctx, src, data) do
|
|
|
|
path = Path.join("posts", md_to_html(src))
|
|
|
|
|
|
|
|
write(ctx, path, data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def write(ctx, name, data) do
|
2024-02-24 08:43:08 -05:00
|
|
|
path = Path.join(ctx.config.output_dir, name)
|
2024-02-16 22:28:13 -05:00
|
|
|
|
|
|
|
with :ok <- File.mkdir_p(Path.dirname(path)) do
|
|
|
|
File.write(path, data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def md_to_html("index.md"), do: "index.html"
|
|
|
|
|
|
|
|
def md_to_html(path) do
|
|
|
|
dir = Path.dirname(path)
|
|
|
|
base = Path.basename(path, ".md")
|
|
|
|
|
|
|
|
case dir do
|
|
|
|
"." -> Path.join(base, "index.html")
|
|
|
|
_ -> Path.join([dir, base, "index.html"])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|