Handle deleting a document
This commit is contained in:
parent
7ad009e1ad
commit
bb77e0572a
@ -37,17 +37,17 @@ defmodule Pandoc do
|
|||||||
stderr_to_stdout: true
|
stderr_to_stdout: true
|
||||||
]
|
]
|
||||||
|
|
||||||
args =
|
new_filename =
|
||||||
List.update_at(args, -1, fn v ->
|
path |> Path.basename() |> String.replace_suffix(".md", ".html") |> String.slice(11..-1//1)
|
||||||
Path.join(
|
|
||||||
v,
|
|
||||||
path
|
|
||||||
|> Path.basename()
|
|
||||||
|> String.replace_suffix(".md", ".html")
|
|
||||||
|> String.slice(11..-1//1)
|
|
||||||
)
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
new_path = args |> List.last() |> Path.join(new_filename)
|
||||||
|
out_path = Path.join(opts[:cd], new_path) |> Path.expand()
|
||||||
|
|
||||||
|
if File.exists?(path) do
|
||||||
|
args = List.replace_at(args, -1, out_path)
|
||||||
"pandoc" |> System.cmd(args ++ [path], opts) |> elem(1)
|
"pandoc" |> System.cmd(args ++ [path], opts) |> elem(1)
|
||||||
|
else
|
||||||
|
File.rm(out_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ defmodule Pandoc.Watcher do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid} = state) do
|
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid} = state) do
|
||||||
case {Path.extname(path), :closed in events} do
|
case {Path.extname(path), :closed in events or :deleted in events} do
|
||||||
{@ext, true} -> Pandoc.run(state[:profile], path)
|
{@ext, true} -> Pandoc.run(state[:profile], path)
|
||||||
_ -> nil
|
_ -> nil
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user