index : pandoc | |
Hex package with a file-watcher and Mix task for using Pandoc to convert Markdown files to HTML. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-12-12 10:54:22 -0800 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-12-12 10:54:22 -0800 |
commit | bb77e0572a0b2aa47168f78fe7565f1fbc84cf98 (patch) | |
tree | 1ab521f9ea1f4610a348903f9be921cb52ec9371 /lib/pandoc.ex | |
parent | 7ad009e1adb16ed88ce6618515d35118a1708a79 (diff) |
Handle deleting a document
Diffstat (limited to 'lib/pandoc.ex')
-rw-r--r-- | lib/pandoc.ex | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/pandoc.ex b/lib/pandoc.ex index 9002bb5..f1f07f7 100644 --- a/lib/pandoc.ex +++ b/lib/pandoc.ex @@ -37,17 +37,17 @@ defmodule Pandoc do stderr_to_stdout: true ] - 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) + new_filename = + path |> Path.basename() |> String.replace_suffix(".md", ".html") |> String.slice(11..-1//1) + + new_path = args |> List.last() |> Path.join(new_filename) + out_path = Path.join(opts[:cd], new_path) |> Path.expand() - "pandoc" |> System.cmd(args ++ [path], opts) |> elem(1) + if File.exists?(path) do + args = List.replace_at(args, -1, out_path) + "pandoc" |> System.cmd(args ++ [path], opts) |> elem(1) + else + File.rm(out_path) + end end end |