feat: more complete metadata diff, scp publishing and rendering context

This commit is contained in:
2026-04-24 06:30:41 +02:00
parent e101a3db79
commit 624b698bb3
48 changed files with 2193 additions and 505 deletions

View File

@@ -16,7 +16,8 @@ defmodule BDS.PreviewTest do
%{project: project, temp_dir: temp_dir}
end
test "start_preview binds localhost and request resolves generated routes, assets, media, and draft previews", %{project: project, temp_dir: temp_dir} do
test "start_preview binds localhost and request resolves generated routes, assets, media, and draft previews",
%{project: project, temp_dir: temp_dir} do
assert {:ok, _metadata} =
Metadata.update_project_metadata(project.id, %{
public_url: "https://example.com/blog",
@@ -24,10 +25,29 @@ defmodule BDS.PreviewTest do
blog_languages: ["en", "de"]
})
assert {:ok, _} = Generation.write_generated_file(project.id, "index.html", "<html>home</html>")
assert {:ok, _} = Generation.write_generated_file(project.id, "de/index.html", "<html>startseite</html>")
assert {:ok, _} = Generation.write_generated_file(project.id, "tag/elixir/index.html", "<html>tag archive</html>")
assert {:ok, _} = Generation.write_generated_file(project.id, "pagefind/pagefind-ui.js", "console.log('pagefind')")
assert {:ok, _} =
Generation.write_generated_file(project.id, "index.html", "<html>home</html>")
assert {:ok, _} =
Generation.write_generated_file(
project.id,
"de/index.html",
"<html>startseite</html>"
)
assert {:ok, _} =
Generation.write_generated_file(
project.id,
"tag/elixir/index.html",
"<html>tag archive</html>"
)
assert {:ok, _} =
Generation.write_generated_file(
project.id,
"pagefind/pagefind-ui.js",
"console.log('pagefind')"
)
media_dir = Path.join([temp_dir, "media", "2026", "04"])
File.mkdir_p!(media_dir)
@@ -46,11 +66,20 @@ defmodule BDS.PreviewTest do
assert server.port == 4123
assert server.is_running == true
assert {:ok, %{body: "<html>home</html>", content_type: "text/html"}} = BDS.Preview.request(project.id, "/")
assert {:ok, %{body: "<html>startseite</html>", content_type: "text/html"}} = BDS.Preview.request(project.id, "/de/")
assert {:ok, %{body: "<html>tag archive</html>", content_type: "text/html"}} = BDS.Preview.request(project.id, "/tag/elixir")
assert {:ok, %{body: "console.log('pagefind')", content_type: "application/javascript"}} = BDS.Preview.request(project.id, "/pagefind/pagefind-ui.js")
assert {:ok, %{body: "media body", content_type: "text/plain"}} = BDS.Preview.request(project.id, "/media/2026/04/image.txt")
assert {:ok, %{body: "<html>home</html>", content_type: "text/html"}} =
BDS.Preview.request(project.id, "/")
assert {:ok, %{body: "<html>startseite</html>", content_type: "text/html"}} =
BDS.Preview.request(project.id, "/de/")
assert {:ok, %{body: "<html>tag archive</html>", content_type: "text/html"}} =
BDS.Preview.request(project.id, "/tag/elixir")
assert {:ok, %{body: "console.log('pagefind')", content_type: "application/javascript"}} =
BDS.Preview.request(project.id, "/pagefind/pagefind-ui.js")
assert {:ok, %{body: "media body", content_type: "text/plain"}} =
BDS.Preview.request(project.id, "/media/2026/04/image.txt")
assert {:ok, %{body: draft_html, content_type: "text/html"}} =
BDS.Preview.preview_draft(project.id, "/draft/draft-post", post.id)
@@ -67,7 +96,8 @@ defmodule BDS.PreviewTest do
project_id: project.id,
title: "Preview Post",
kind: :post,
content: "<article class=\"preview-template\"><h1>{{ post.title }}</h1><div>{{ post.content }}</div></article>"
content:
"<article class=\"preview-template\"><h1>{{ post.title }}</h1><div>{{ post.content }}</div></article>"
})
assert {:ok, published_template} = BDS.Templates.publish_template(template.id)
@@ -93,7 +123,9 @@ defmodule BDS.PreviewTest do
assert :ok = BDS.Preview.stop_preview(project.id)
end
test "draft preview renders through copied starter templates with markdown and i18n", %{project: project} do
test "draft preview renders through copied starter templates with markdown and i18n", %{
project: project
} do
assert {:ok, _menu} =
BDS.Menu.update_menu(project.id, [
%{kind: :page, label: "Notes", slug: "notes"}
@@ -126,7 +158,8 @@ defmodule BDS.PreviewTest do
assert :ok = BDS.Preview.stop_preview(project.id)
end
test "preview renders not-found template for missing routes and rewrites markdown macros and canonical URLs", %{project: project, temp_dir: temp_dir} do
test "preview renders not-found template for missing routes and rewrites markdown macros and canonical URLs",
%{project: project, temp_dir: temp_dir} do
:inets.start()
assert {:ok, _metadata} =
@@ -157,7 +190,10 @@ defmodule BDS.PreviewTest do
assert {:ok, published_linked_post} = Posts.publish_post(linked_post.id)
media_source_reference = "/" <> Path.join(Path.dirname(media.file_path), media.original_name)
canonical_post_href = "/" <> String.trim_trailing(BDS.Generation.post_output_path(published_linked_post), "index.html")
canonical_post_href =
"/" <>
String.trim_trailing(BDS.Generation.post_output_path(published_linked_post), "index.html")
assert {:ok, post} =
Posts.create_post(%{
@@ -190,14 +226,21 @@ defmodule BDS.PreviewTest do
assert missing_body =~ ~s(data-template="not-found")
assert {:ok, {{_version, 404, _reason}, _headers, body}} =
:httpc.request(:get, {to_charlist("http://#{server.host}:#{server.port}/missing-page"), []}, [], body_format: :binary)
:httpc.request(
:get,
{to_charlist("http://#{server.host}:#{server.port}/missing-page"), []},
[],
body_format: :binary
)
assert body =~ ~s(data-template="not-found")
assert :ok = BDS.Preview.stop_preview(project.id)
end
test "start_preview serves generated and draft routes over real HTTP on localhost", %{project: project} do
test "start_preview serves generated and draft routes over real HTTP on localhost", %{
project: project
} do
:inets.start()
assert {:ok, _metadata} =
@@ -207,7 +250,8 @@ defmodule BDS.PreviewTest do
blog_languages: ["en"]
})
assert {:ok, _} = Generation.write_generated_file(project.id, "index.html", "<html>http home</html>")
assert {:ok, _} =
Generation.write_generated_file(project.id, "index.html", "<html>http home</html>")
assert {:ok, post} =
Posts.create_post(%{
@@ -220,13 +264,26 @@ defmodule BDS.PreviewTest do
assert {:ok, server} = BDS.Preview.start_preview(project.id)
assert {:ok, {{_version, 200, _reason}, headers, body}} =
:httpc.request(:get, {to_charlist("http://#{server.host}:#{server.port}/"), []}, [], body_format: :binary)
:httpc.request(:get, {to_charlist("http://#{server.host}:#{server.port}/"), []}, [],
body_format: :binary
)
assert body == "<html>http home</html>"
assert Enum.any?(headers, fn {name, value} -> String.downcase(to_string(name)) == "content-type" and to_string(value) =~ "text/html" end)
assert Enum.any?(headers, fn {name, value} ->
String.downcase(to_string(name)) == "content-type" and
to_string(value) =~ "text/html"
end)
assert {:ok, {{_version, 200, _reason}, _headers, draft_body}} =
:httpc.request(:get, {to_charlist("http://#{server.host}:#{server.port}/draft/http-draft?post_id=#{post.id}"), []}, [], body_format: :binary)
:httpc.request(
:get,
{to_charlist(
"http://#{server.host}:#{server.port}/draft/http-draft?post_id=#{post.id}"
), []},
[],
body_format: :binary
)
assert draft_body =~ "Draft over HTTP"