Web Dev Solutions

Catalin Mititiuc

From 6fc8e8ec192051938da4d31459698d55b1e40ea2 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Thu, 5 Dec 2024 14:00:23 -0800 Subject: Get path data from config vars --- lib/pandoc.ex | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'lib/pandoc.ex') diff --git a/lib/pandoc.ex b/lib/pandoc.ex index 336aeec..1c3970d 100644 --- a/lib/pandoc.ex +++ b/lib/pandoc.ex @@ -3,32 +3,16 @@ defmodule Pandoc do 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)}" - ) + def run(profile, ["--watch"]) do + IO.puts(""" - # Application.get_env(:pandoc, profile) |> inspect(pretty: true) |> IO.puts() + Pandoc watcher starting, env: #{Application.get_env(:pandoc, profile) |> inspect(pretty: true)} + """) ref = __MODULE__.Supervisor |> Supervisor.start_child( - Supervisor.child_spec({Pandoc.Watcher, [profile, dirs: ["priv/posts"]]}, + Supervisor.child_spec({Pandoc.Watcher, [profile, dirs: ["documents"]]}, restart: :transient, id: __MODULE__.Watcher ) @@ -43,4 +27,34 @@ defmodule Pandoc do {:DOWN, ^ref, _, _, _} -> :ok end end + + def run(profile, extra_args) do + config = Application.get_env(:pandoc, profile) + args = config[:args] || [] + + opts = [ + cd: config[:cd] || File.cwd!(), + into: IO.stream(:stdio, :line), + stderr_to_stdout: true + ] + + [path] = extra_args + + args = + List.update_at(args, -1, fn v -> + Path.join( + v, + path + |> Path.basename() + |> String.replace_suffix(".md", ".html") + |> String.slice(11..-1//1) + ) + end) + + IO.puts(""" + System command running: #{inspect(Enum.join(["pandoc" | args ++ extra_args], " "))} + """) + + "pandoc" |> System.cmd(args ++ extra_args, opts) |> elem(1) + end end -- cgit v1.2.3