defmodule Pandoc do
@moduledoc """
Documentation for `Pandoc`.
"""
def install_and_run(path) do
System.cmd("pandoc", [
"--mathjax",
path,
"-o",
Path.join(
"priv/static/posts",
Path.basename(path)
|> String.replace_suffix(".md", ".html")
|> String.slice(11..-1//1)
)
])
end
def install_and_run(profile, ["--watch"]) do
# Application.get_env(:pandoc, a1) |> inspect(pretty: true) |> IO.puts
IO.puts(
"Pandoc watcher starting, env: #{Application.get_env(:pandoc, profile) |> inspect(pretty: true)}"
)
# Application.get_env(:pandoc, profile) |> inspect(pretty: true) |> IO.puts()
ref =
__MODULE__.Supervisor
|> Supervisor.start_child(
Supervisor.child_spec({Pandoc.Watcher, [profile, dirs: ["priv/posts"]]},
restart: :transient,
id: __MODULE__.Watcher
)
)
|> case do
{:ok, pid} -> pid
{:error, {:already_started, pid}} -> pid
end
|> Process.monitor()
receive do
{:DOWN, ^ref, _, _, _} -> :ok
end
end
end