fix: more fixes to file formats

This commit is contained in:
2026-04-25 11:35:36 +02:00
parent 5ecd90ae65
commit b90a4569da
18 changed files with 477 additions and 181 deletions

View File

@@ -43,16 +43,17 @@ defmodule BDS.MediaTest do
sidecar = File.read!(Path.join(temp_dir, media.sidecar_path))
assert sidecar =~ "id: #{media.id}\n"
assert sidecar =~ "original_name: sample.txt\n"
assert sidecar =~ "mime_type: text/plain\n"
assert sidecar =~ "originalName: sample.txt\n"
assert sidecar =~ "mimeType: text/plain\n"
assert sidecar =~ "title: Sample\n"
assert sidecar =~ "alt: Alt text\n"
assert sidecar =~ "caption: Caption\n"
assert sidecar =~ "author: Writer\n"
assert sidecar =~ "language: en\n"
assert sidecar =~ "tags:\n - alpha\n"
assert sidecar =~ ~r/created_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert sidecar =~ ~r/updated_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert sidecar =~ "linkedPostIds:\n"
assert sidecar =~ ~r/createdAt: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert sidecar =~ ~r/updatedAt: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
refute File.exists?(Path.join(temp_dir, media.sidecar_path <> ".tmp"))
end
@@ -130,8 +131,8 @@ defmodule BDS.MediaTest do
sidecar_path,
[
"id: media-from-file",
"original_name: original.jpg",
"mime_type: image/jpeg",
"originalName: original.jpg",
"mimeType: image/jpeg",
"size: #{byte_size(tiny_jpeg_binary())}",
"width: 3",
"height: 2",
@@ -140,8 +141,10 @@ defmodule BDS.MediaTest do
"caption: Recovered caption",
"author: Writer",
"language: en",
"created_at: 2024-03-30T21:20:00.000Z",
"updated_at: 2024-03-31T21:20:00.000Z",
"createdAt: 2024-03-30T21:20:00.000Z",
"updatedAt: 2024-03-31T21:20:00.000Z",
"linkedPostIds:",
" - post-a",
"tags:",
" - alpha",
""
@@ -152,7 +155,7 @@ defmodule BDS.MediaTest do
File.write!(
binary_path <> ".de.meta",
[
"translation_for: media-from-file",
"translationFor: media-from-file",
"language: de",
"title: Titel",
"alt: Alt text",
@@ -371,7 +374,7 @@ defmodule BDS.MediaTest do
translated_sidecar_path = Path.join(temp_dir, media.file_path <> ".de.meta")
contents = File.read!(translated_sidecar_path)
assert contents =~ "translation_for: #{media.id}\n"
assert contents =~ "translationFor: #{media.id}\n"
assert contents =~ "language: de\n"
assert contents =~ "title: Titel\n"
assert contents =~ "alt: Alt text\n"

View File

@@ -44,16 +44,16 @@ defmodule BDS.MenuTest do
assert File.exists?(opml_path)
contents = File.read!(opml_path)
assert contents =~ ~s(<outline kind="home" text="Home")
assert contents =~ ~s(<outline kind="page" text="About" slug="about")
assert contents =~ ~s(<outline kind="submenu" text="Sections")
assert contents =~ ~s(<outline kind="category_archive" text="Notes" slug="notes")
assert contents =~ ~s(<outline text="Home" type="home" pageSlug="home")
assert contents =~ ~s(<outline text="About" type="page" pageSlug="about")
assert contents =~ ~s(<outline text="Sections" type="submenu")
assert contents =~ ~s(<outline text="Notes" type="category-archive" categoryName="notes")
assert {:ok, loaded} = BDS.Menu.get_menu(project.id)
assert loaded == menu
end
test "sync_menu_from_filesystem loads canonical OPML and preserves a prepended Home entry", %{
test "sync_menu_from_filesystem loads canonical bDS OPML and preserves a prepended Home entry", %{
project: project,
temp_dir: temp_dir
} do
@@ -65,10 +65,14 @@ defmodule BDS.MenuTest do
[
~s(<?xml version="1.0" encoding="UTF-8"?>),
~s(<opml version="2.0">),
~s( <head>),
~s( <title>Blog Menu</title>),
~s( </head>),
~s( <body>),
~s( <outline kind="page" text="Blog" slug="blog" />),
~s( <outline kind="submenu" text="Topics">),
~s( <outline kind="category_archive" text="Elixir" slug="elixir" />),
~s( <outline id="menu-home" text="Home" type="home" pageSlug="home"/>),
~s( <outline id="menu-topics" text="Topics" type="submenu">),
~s( <outline id="menu-page" text="Blog" type="page" pageId="page-1" pageSlug="blog"/>),
~s( <outline id="menu-cat" text="Elixir" type="category-archive" categoryName="elixir"/>),
~s( </outline>),
~s( </body>),
~s(</opml>)
@@ -80,12 +84,12 @@ defmodule BDS.MenuTest do
assert menu.items == [
%{kind: :home, label: "Home", slug: nil},
%{kind: :page, label: "Blog", slug: "blog"},
%{
kind: :submenu,
label: "Topics",
slug: nil,
children: [
%{kind: :page, label: "Blog", slug: "blog"},
%{kind: :category_archive, label: "Elixir", slug: "elixir"}
]
}

View File

@@ -38,14 +38,14 @@ defmodule BDS.MetadataTest do
assert %{
"name" => "Renamed Blog",
"description" => "Description",
"public_url" => "https://example.com",
"main_language" => "en",
"default_author" => "Writer",
"max_posts_per_page" => 25,
"blogmark_category" => "links",
"pico_theme" => "blue",
"semantic_similarity_enabled" => true,
"blog_languages" => ["de", "fr"]
"publicUrl" => "https://example.com",
"mainLanguage" => "en",
"defaultAuthor" => "Writer",
"maxPostsPerPage" => 25,
"blogmarkCategory" => "links",
"picoTheme" => "blue",
"semanticSimilarityEnabled" => true,
"blogLanguages" => ["de", "fr"]
} = Jason.decode!(File.read!(project_json_path))
assert {:ok, loaded} = BDS.Metadata.get_project_metadata(project.id)
@@ -78,25 +78,23 @@ 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 %{"categories" => ["article", "aside", "news", "page", "picture"]} =
assert ["article", "aside", "news", "page", "picture"] =
Jason.decode!(File.read!(categories_path))
assert %{
"categories" => %{
"news" => %{
"render_in_lists" => false,
"show_title" => true,
"post_template_slug" => "article",
"list_template_slug" => "listing"
}
"news" => %{
"renderInLists" => false,
"showTitle" => true,
"postTemplateSlug" => "article",
"listTemplateSlug" => "listing"
}
} = Jason.decode!(File.read!(category_meta_path))
assert %{
"ssh_host" => "example.com",
"ssh_user" => "deploy",
"ssh_remote_path" => "/srv/site",
"ssh_mode" => "rsync"
"sshHost" => "example.com",
"sshUser" => "deploy",
"sshRemotePath" => "/srv/site",
"sshMode" => "rsync"
} = Jason.decode!(File.read!(publishing_path))
assert {:ok, synced} = BDS.Metadata.sync_project_metadata_from_filesystem(project.id)
@@ -117,6 +115,87 @@ defmodule BDS.MetadataTest do
}
end
test "sync_project_metadata_from_filesystem reads canonical bDS metadata file shapes", %{
project: project,
temp_dir: temp_dir
} do
meta_dir = Path.join(temp_dir, "meta")
File.mkdir_p!(meta_dir)
File.write!(
Path.join(meta_dir, "project.json"),
Jason.encode!(%{
"name" => "Legacy Blog",
"description" => "Imported",
"publicUrl" => "https://legacy.example",
"mainLanguage" => "de",
"defaultAuthor" => "Legacy Writer",
"maxPostsPerPage" => 17,
"blogmarkCategory" => "aside",
"picoTheme" => "slate",
"semanticSimilarityEnabled" => true,
"blogLanguages" => ["en"]
})
)
File.write!(
Path.join(meta_dir, "categories.json"),
Jason.encode!(["article", "aside", "legacy", "page", "picture"])
)
File.write!(
Path.join(meta_dir, "category-meta.json"),
Jason.encode!(%{
"legacy" => %{
"renderInLists" => false,
"showTitle" => true,
"postTemplateSlug" => "feature-view",
"listTemplateSlug" => "feature-list",
"title" => "Legacy"
}
})
)
File.write!(
Path.join(meta_dir, "publishing.json"),
Jason.encode!(%{
"sshHost" => "legacy.example",
"sshUser" => "deploy",
"sshRemotePath" => "/srv/legacy",
"sshMode" => "rsync"
})
)
assert {:ok, synced} = BDS.Metadata.sync_project_metadata_from_filesystem(project.id)
assert synced.name == "Legacy Blog"
assert synced.description == "Imported"
assert synced.public_url == "https://legacy.example"
assert synced.main_language == "de"
assert synced.default_author == "Legacy Writer"
assert synced.max_posts_per_page == 17
assert synced.blogmark_category == "aside"
assert synced.pico_theme == "slate"
assert synced.semantic_similarity_enabled == true
assert synced.blog_languages == ["en"]
assert synced.categories == ["article", "aside", "legacy", "page", "picture"]
assert synced.category_settings["legacy"] == %{
"render_in_lists" => false,
"show_title" => true,
"post_template_slug" => "feature-view",
"list_template_slug" => "feature-list",
"title" => "Legacy"
}
assert synced.publishing_preferences == %{
"ssh_host" => "legacy.example",
"ssh_user" => "deploy",
"ssh_remote_path" => "/srv/legacy",
"ssh_mode" => "rsync"
}
end
test "enabling semantic similarity backfills embeddings for existing published posts", %{
project: project
} do

View File

@@ -56,6 +56,7 @@ defmodule BDS.PostTranslationsTest do
assert File.exists?(translation_path)
translation_contents = File.read!(translation_path)
assert translation_contents =~ "translationFor: #{post.id}\n"
assert translation_contents =~ "title: Kanonischer Beitrag\n"
assert translation_contents =~ "language: de\n"
assert translation_contents =~ "status: published\n"
@@ -124,13 +125,13 @@ defmodule BDS.PostTranslationsTest do
[
"---",
"id: orphan-translation",
"translation_for: missing-post",
"translationFor: missing-post",
"language: fr",
"title: Orpheline",
"status: published",
"created_at: 1711843200",
"updated_at: 1711929600",
"published_at: 1712016000",
"createdAt: 1711843200",
"updatedAt: 1711929600",
"publishedAt: 1712016000",
"---",
"Texte orphelin",
""

View File

@@ -147,13 +147,13 @@ defmodule BDS.PostsTest do
assert file_contents =~ "excerpt: Summary\n"
assert file_contents =~ "author: Writer\n"
assert file_contents =~ "language: en\n"
assert file_contents =~ "do_not_translate: true\n"
assert file_contents =~ "template_slug: article\n"
assert file_contents =~ "doNotTranslate: true\n"
assert file_contents =~ "templateSlug: article\n"
assert file_contents =~ "tags:\n - alpha\n"
assert file_contents =~ "categories:\n - notes\n"
assert file_contents =~ ~r/created_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert file_contents =~ ~r/updated_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert file_contents =~ ~r/published_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert file_contents =~ ~r/createdAt: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert file_contents =~ ~r/updatedAt: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert file_contents =~ ~r/publishedAt: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert file_contents =~ "\n---\nHello from markdown\n"
refute File.exists?(full_path <> ".tmp")
@@ -274,11 +274,11 @@ defmodule BDS.PostsTest do
"status: published",
"author: Writer",
"language: en",
"do_not_translate: true",
"template_slug: article",
"created_at: 2024-03-30T21:20:00.000Z",
"updated_at: 2024-03-31T21:20:00.000Z",
"published_at: 2024-04-01T21:20:00.000Z",
"doNotTranslate: true",
"templateSlug: article",
"createdAt: 2024-03-30T21:20:00.000Z",
"updatedAt: 2024-03-31T21:20:00.000Z",
"publishedAt: 2024-04-01T21:20:00.000Z",
"tags:",
" - alpha",
"categories:",
@@ -313,7 +313,7 @@ defmodule BDS.PostsTest do
assert post.content == nil
end
test "rebuild_posts_from_files imports legacy old-app translation files alongside canonical posts" do
test "rebuild_posts_from_files imports canonical bDS translation files alongside canonical posts" do
temp_dir =
Path.join(System.tmp_dir!(), "bds-post-rebuild-legacy-#{System.unique_integer([:positive])}")

View File

@@ -65,14 +65,15 @@ defmodule BDS.ScriptsTest do
contents = File.read!(full_path)
assert contents =~ "---\nid: #{published.id}\n"
assert contents =~ "projectId: #{project.id}\n"
assert contents =~ "slug: process-feed\n"
assert contents =~ "title: Process Feed\n"
assert contents =~ "kind: utility\n"
assert contents =~ "entrypoint: main\n"
assert contents =~ "enabled: true\n"
assert contents =~ "version: 1\n"
assert contents =~ ~r/created_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert contents =~ ~r/updated_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert contents =~ ~r/createdAt: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert contents =~ ~r/updatedAt: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert contents =~ "\n---\nfunction main() return 'ok' end\n"
refute File.exists?(full_path <> ".tmp")
end
@@ -139,14 +140,15 @@ defmodule BDS.ScriptsTest do
[
"---",
"id: script-from-file",
"projectId: #{project.id}",
"slug: recovered",
"title: Recovered Script",
"kind: utility",
"entrypoint: main",
"enabled: true",
"version: 4",
"created_at: 1970-01-01T00:00:00.301Z",
"updated_at: 1970-01-01T00:00:00.404Z",
"createdAt: 1970-01-01T00:00:00.301Z",
"updatedAt: 1970-01-01T00:00:00.404Z",
"---",
"function main() return 'restored' end",
""

View File

@@ -30,7 +30,7 @@ defmodule BDS.TagsTest do
tags_path = Path.join([temp_dir, "meta", "tags.json"])
assert File.exists?(tags_path)
assert %{"tags" => [%{"name" => "Alpha"}, %{"color" => "#000000", "name" => "Zebra"}]} =
assert [%{"name" => "Alpha"}, %{"color" => "#000000", "name" => "Zebra"}] =
Jason.decode!(File.read!(tags_path))
end
@@ -59,11 +59,9 @@ defmodule BDS.TagsTest do
tags_path = Path.join([temp_dir, "meta", "tags.json"])
assert %{
"tags" => [
%{"name" => "Alpha", "color" => "#112233", "post_template_slug" => "article"}
]
} =
assert [
%{"name" => "Alpha", "color" => "#112233", "postTemplateSlug" => "article"}
] =
Jason.decode!(File.read!(tags_path))
end
@@ -93,7 +91,7 @@ defmodule BDS.TagsTest do
assert contents =~ "\n---\nBody\n"
tags_path = Path.join([temp_dir, "meta", "tags.json"])
assert %{"tags" => [%{"name" => "Beta"}]} = Jason.decode!(File.read!(tags_path))
assert [%{"name" => "Beta"}] = Jason.decode!(File.read!(tags_path))
end
test "merge_tags moves source tags onto the target, deduplicates post tags, deletes sources, and refreshes tags.json",
@@ -126,7 +124,7 @@ defmodule BDS.TagsTest do
assert contents =~ "\n---\nBody\n"
tags_path = Path.join([temp_dir, "meta", "tags.json"])
assert %{"tags" => [%{"name" => "Gamma"}]} = Jason.decode!(File.read!(tags_path))
assert [%{"name" => "Gamma"}] = Jason.decode!(File.read!(tags_path))
end
test "delete_tag removes the tag from posts, rewrites published files, deletes the row, and refreshes tags.json",
@@ -157,7 +155,7 @@ defmodule BDS.TagsTest do
assert contents =~ "\n---\nBody\n"
tags_path = Path.join([temp_dir, "meta", "tags.json"])
assert %{"tags" => [%{"name" => "Beta"}]} = Jason.decode!(File.read!(tags_path))
assert [%{"name" => "Beta"}] = Jason.decode!(File.read!(tags_path))
end
test "sync_tags_from_posts creates missing tags from post tag arrays and refreshes tags.json",
@@ -196,17 +194,15 @@ defmodule BDS.TagsTest do
tags_path = Path.join([temp_dir, "meta", "tags.json"])
assert %{
"tags" => [
%{"name" => "Another"},
%{
"name" => "Existing",
"color" => "#112233",
"post_template_slug" => "feature-view"
},
%{"name" => "Missing"}
]
} = Jason.decode!(File.read!(tags_path))
assert [
%{"name" => "Another"},
%{
"name" => "Existing",
"color" => "#112233",
"postTemplateSlug" => "feature-view"
},
%{"name" => "Missing"}
] = Jason.decode!(File.read!(tags_path))
end
defp errors_on(changeset) do

View File

@@ -66,13 +66,14 @@ defmodule BDS.TemplatesTest do
contents = File.read!(full_path)
assert contents =~ "---\nid: #{published.id}\n"
assert contents =~ "projectId: #{project.id}\n"
assert contents =~ "slug: landing-page\n"
assert contents =~ "title: Landing Page\n"
assert contents =~ "kind: list\n"
assert contents =~ "enabled: true\n"
assert contents =~ "version: 1\n"
assert contents =~ ~r/created_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert contents =~ ~r/updated_at: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert contents =~ ~r/createdAt: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert contents =~ ~r/updatedAt: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\n/
assert contents =~ "\n---\n<section>{{ page_title }}</section>\n"
refute File.exists?(full_path <> ".tmp")
end
@@ -153,7 +154,7 @@ defmodule BDS.TemplatesTest do
assert post_contents =~ "\n---\nBody\n"
tags_path = Path.join([temp_dir, "meta", "tags.json"])
assert %{"tags" => [%{"name" => "Feature"}]} = Jason.decode!(File.read!(tags_path))
assert [%{"name" => "Feature"}] = Jason.decode!(File.read!(tags_path))
end
test "update_template cascades slug changes to posts and tags and renames the published file",
@@ -208,12 +209,12 @@ defmodule BDS.TemplatesTest do
assert template_contents =~ "\n---\n<article>{{ content }}</article>\n"
post_contents = File.read!(Path.join(temp_dir, reloaded_post.file_path))
assert post_contents =~ "template_slug: feature-view\n"
assert post_contents =~ "templateSlug: feature-view\n"
assert post_contents =~ "\n---\nBody\n"
tags_path = Path.join([temp_dir, "meta", "tags.json"])
assert %{"tags" => [%{"name" => "Feature", "post_template_slug" => "feature-view"}]} =
assert [%{"name" => "Feature", "postTemplateSlug" => "feature-view"}] =
Jason.decode!(File.read!(tags_path))
end
@@ -231,13 +232,14 @@ defmodule BDS.TemplatesTest do
[
"---",
"id: template-from-file",
"projectId: #{project.id}",
"slug: recovered-view",
"title: Recovered View",
"kind: list",
"enabled: true",
"version: 3",
"created_at: 1970-01-01T00:00:00.101Z",
"updated_at: 1970-01-01T00:00:00.202Z",
"createdAt: 1970-01-01T00:00:00.101Z",
"updatedAt: 1970-01-01T00:00:00.202Z",
"---",
"<section>Recovered</section>",
""