fix: pretty-print json on serialisation to filesystem

This commit is contained in:
2026-05-30 21:58:31 +02:00
parent c1b7ceae6c
commit 70d2342274
4 changed files with 11 additions and 3 deletions

View File

@@ -417,7 +417,7 @@ defmodule BDS.Metadata do
defp write_json(project, file_name, payload) do
meta_dir = Path.join(Projects.project_data_dir(project), "meta")
path = Path.join(meta_dir, file_name)
Persistence.atomic_write(path, Jason.encode!(payload))
Persistence.atomic_write(path, Jason.encode!(payload, pretty: true))
end
defp read_json(project, file_name) do

View File

@@ -269,7 +269,7 @@ defmodule BDS.Tags do
|> maybe_put("postTemplateSlug", tag.post_template_slug)
end)
Persistence.atomic_write(path, Jason.encode!(payload))
Persistence.atomic_write(path, Jason.encode!(payload, pretty: true))
end
defp validate_unique_name(project_id, name) do

View File

@@ -99,6 +99,10 @@ defmodule BDS.MetadataTest do
category_meta_path = Path.join([temp_dir, "meta", "category-meta.json"])
publishing_path = Path.join([temp_dir, "meta", "publishing.json"])
assert File.read!(categories_path) =~ "\n"
assert File.read!(category_meta_path) =~ "\n"
assert File.read!(publishing_path) =~ "\n"
assert ["article", "aside", "news", "page", "picture"] =
Jason.decode!(File.read!(categories_path))

View File

@@ -30,8 +30,12 @@ defmodule BDS.TagsTest do
tags_path = Path.join([temp_dir, "meta", "tags.json"])
assert File.exists?(tags_path)
contents = File.read!(tags_path)
assert contents =~ "\n"
refute String.contains?(contents, "}],[")
assert [%{"name" => "Alpha"}, %{"color" => "#000000", "name" => "Zebra"}] =
Jason.decode!(File.read!(tags_path))
Jason.decode!(contents)
end
test "create_tag rejects case-insensitive duplicates per project", %{project: project} do