From 9e8392a939825a8920004922d51b123b1a92b6b9 Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Wed, 11 Dec 2024 16:59:15 -0800
Subject: Get path from config in mix task
---
lib/mix/tasks/pandoc.ex | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
(limited to 'lib/mix/tasks/pandoc.ex')
diff --git a/lib/mix/tasks/pandoc.ex b/lib/mix/tasks/pandoc.ex
index 4da8bf1..94d7dd5 100644
--- a/lib/mix/tasks/pandoc.ex
+++ b/lib/mix/tasks/pandoc.ex
@@ -1,6 +1,8 @@
defmodule Mix.Tasks.Pandoc do
use Mix.Task
+ @ext ".md"
+
@impl true
def run(args) do
switches = [runtime_config: :boolean]
@@ -17,15 +19,17 @@ defmodule Mix.Tasks.Pandoc do
install_and_run(remaining_args)
end
- defp install_and_run([profile | args] = _all) do
- IO.puts("mix task args #{inspect(args)}")
+ defp install_and_run([profile | _args] = all) do
+ IO.puts("Converting markdown...")
- "documents"
- |> File.ls!()
- |> Enum.each(fn path ->
- all = [profile, path]
+ profile = String.to_atom(profile)
+ config = Application.get_env(:pandoc, profile)
- case Pandoc.run(String.to_atom(profile), [path]) do
+ (config[:cd] || File.cwd!())
+ |> Path.join("*#{@ext}")
+ |> Path.wildcard()
+ |> Enum.each(fn path ->
+ case Pandoc.run(profile, Path.basename(path)) do
0 -> :ok
status -> Mix.raise("`mix pandoc #{Enum.join(all, " ")}` exited with #{status}")
end
--
cgit v1.2.3