feat: preview working and template delete is in, too

This commit is contained in:
2026-04-26 19:53:29 +02:00
parent 09a1dcede3
commit 92e5c2ccfd
15 changed files with 401 additions and 42 deletions

View File

@@ -155,6 +155,8 @@ defmodule BDS.Templates do
template
end)
remove_stale_published_templates(project_id, project, template_paths)
{:ok, templates}
end
@@ -380,6 +382,29 @@ defmodule BDS.Templates do
|> Repo.insert_or_update!()
end
defp remove_stale_published_templates(project_id, project, template_paths) do
tracked_paths =
template_paths
|> Enum.map(&Path.relative_to(&1, Projects.project_data_dir(project)))
|> MapSet.new()
Repo.all(
from template in Template,
where:
template.project_id == ^project_id and
template.status == :published and
template.file_path != "" and
not is_nil(template.file_path)
)
|> Enum.reject(&(MapSet.member?(tracked_paths, &1.file_path) or File.exists?(full_file_path(project_id, &1.file_path))))
|> Enum.each(fn template ->
clear_template_references(template)
Repo.delete!(template)
end)
:ok
end
defp parse_template_kind(kind) when is_atom(kind), do: kind
defp parse_template_kind("post"), do: :post
defp parse_template_kind("list"), do: :list