fix: issue #11 wrong page titles compared to old app

This commit is contained in:
2026-07-05 12:58:44 +02:00
parent cf1d4bd46f
commit 28398b17f4
8 changed files with 208 additions and 10 deletions

View File

@@ -0,0 +1,93 @@
defmodule BDS.Generation.PageTitleParityTest do
use ExUnit.Case, async: false
alias BDS.Generation
@blog_description "My Wonderful Blog"
setup do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BDS.Repo)
temp_dir = Path.join(System.tmp_dir!(), "bds-page-title-#{System.unique_integer([:positive])}")
File.mkdir_p!(temp_dir)
on_exit(fn -> File.rm_rf(temp_dir) end)
{:ok, project} = BDS.Projects.create_project(%{name: "PageTitleBlog", data_path: temp_dir})
{:ok, _} =
BDS.Metadata.update_project_metadata(project.id, %{
main_language: "en",
description: @blog_description
})
{:ok, post} =
BDS.Posts.create_post(%{
project_id: project.id,
title: "Hello Post",
content: "Body of the hello post",
categories: ["article"],
tags: ["news"],
language: "en"
})
{:ok, _} = BDS.Posts.publish_post(post.id)
%{project: project, temp_dir: temp_dir}
end
defp read_html(temp_dir, segments) do
path = Path.join([temp_dir, "html"] ++ segments ++ ["index.html"])
assert File.exists?(path), "expected page at #{Enum.join(segments, "/")}"
File.read!(path)
end
defp document_title(html) do
case Regex.run(~r{<title>(.*?)</title>}s, html) do
[_, title] -> String.trim(title)
_ -> nil
end
end
test "home page document title is the blog title", %{project: project, temp_dir: temp_dir} do
{:ok, _} = Generation.render_site_section(project.id, :core)
home_html = read_html(temp_dir, [])
assert document_title(home_html) == @blog_description
end
test "archive document titles are the blog title while headings show the label", %{
project: project,
temp_dir: temp_dir
} do
{:ok, _} = Generation.render_site_section(project.id, :category)
{:ok, _} = Generation.render_site_section(project.id, :tag)
category_html = read_html(temp_dir, ["category", "article"])
tag_html = read_html(temp_dir, ["tag", "news"])
assert document_title(category_html) == @blog_description
assert document_title(tag_html) == @blog_description
assert category_html =~ ~s(<h1 class="archive-heading">article</h1>)
assert tag_html =~ ~s(<h1 class="archive-heading">news</h1>)
end
test "category archive heading uses the configured descriptive title", %{
project: project,
temp_dir: temp_dir
} do
{:ok, _} =
BDS.Metadata.update_category_settings(project.id, "article", %{
"render_in_lists" => true,
"show_title" => true,
"title" => "Long Form Articles"
})
{:ok, _} = Generation.render_site_section(project.id, :category)
category_html = read_html(temp_dir, ["category", "article"])
assert category_html =~ ~s(<h1 class="archive-heading">Long Form Articles</h1>)
refute category_html =~ ~s(<h1 class="archive-heading">article</h1>)
assert document_title(category_html) == @blog_description
end
end

View File

@@ -562,6 +562,47 @@ defmodule BDS.PreviewTest do
assert :ok = BDS.Preview.stop_preview(project.id)
end
test "on-demand rendering: document title is the blog title on home and archives", %{
project: project
} do
assert {:ok, _metadata} =
Metadata.update_project_metadata(project.id, %{
main_language: "en",
blog_languages: ["en"],
description: "My Preview Blog"
})
assert {:ok, _} =
Metadata.update_category_settings(project.id, "article", %{
"render_in_lists" => true,
"show_title" => true,
"title" => "Long Form Articles"
})
assert {:ok, post} =
Posts.create_post(%{
project_id: project.id,
title: "Article Post",
content: "Article body",
language: "en",
categories: ["article"]
})
assert {:ok, _published} = Posts.publish_post(post.id)
assert {:ok, _server} = BDS.Preview.start_preview(project.id)
assert {:ok, %{body: home_html}} = BDS.Preview.request(project.id, "/")
assert home_html =~ "<title>My Preview Blog</title>"
assert {:ok, %{body: category_html}} =
BDS.Preview.request(project.id, "/category/article")
assert category_html =~ "<title>My Preview Blog</title>"
assert category_html =~ ~s(<h1 class="archive-heading">Long Form Articles</h1>)
assert :ok = BDS.Preview.stop_preview(project.id)
end
test "on-demand rendering: tag archive renders filtered posts", %{project: project} do
assert {:ok, _metadata} =
Metadata.update_project_metadata(project.id, %{