fix: issue #6 had missing title suppression

This commit is contained in:
2026-07-05 12:39:59 +02:00
parent 7fa6e6232c
commit cf1d4bd46f
3 changed files with 59 additions and 4 deletions

View File

@@ -136,6 +136,8 @@ defmodule BDS.Rendering.ListArchive do
end
defp normalize_list_posts(ctx, posts, language) do
show_title_by_category = show_title_by_category(ctx.metadata)
Enum.map(posts, fn post ->
post_id = MapUtils.attr(post, :id)
post_record = Map.get(ctx.record_by_id, post_id)
@@ -147,6 +149,9 @@ defmodule BDS.Rendering.ListArchive do
MapUtils.attr(post, :excerpt, "")
)
categories =
MapUtils.attr(post, :categories, record_list(post_record, :categories)) || []
%{
id: MapUtils.attr(post, :id),
slug: MapUtils.attr(post, :slug),
@@ -161,8 +166,7 @@ defmodule BDS.Rendering.ListArchive do
created_at: MapUtils.attr(post, :created_at, record_value(post_record, :created_at)),
updated_at: MapUtils.attr(post, :updated_at, record_value(post_record, :updated_at)),
tags: MapUtils.attr(post, :tags, record_list(post_record, :tags)) || [],
categories:
MapUtils.attr(post, :categories, record_list(post_record, :categories)) || [],
categories: categories,
template_slug:
MapUtils.attr(post, :template_slug, record_value(post_record, :template_slug)),
do_not_translate:
@@ -172,7 +176,7 @@ defmodule BDS.Rendering.ListArchive do
record_value(post_record, :do_not_translate, false)
),
href: MapUtils.attr(post, :href),
show_title: true,
show_title: show_list_title?(categories, show_title_by_category),
linked_media: [],
outgoing_links: [],
incoming_links: []
@@ -180,6 +184,39 @@ defmodule BDS.Rendering.ListArchive do
end)
end
# A post's title is hidden in list/archive pages when any of its categories
# has "show title" turned off. Mirrors the single-post behaviour so that, for
# example, asides render as body-only entries everywhere.
defp show_list_title?([], _show_title_by_category), do: true
defp show_list_title?(categories, show_title_by_category) do
not Enum.any?(categories, fn category ->
Map.get(show_title_by_category, category, true) == false
end)
end
@default_show_title_by_category %{
"article" => true,
"picture" => true,
"aside" => false,
"page" => true
}
defp show_title_by_category(metadata) do
settings = Map.get(metadata, :category_settings, %{}) || %{}
Enum.reduce(settings, @default_show_title_by_category, fn {category, category_settings}, acc ->
Map.put(acc, category, category_show_title?(category_settings))
end)
end
defp category_show_title?(settings) do
case MapUtils.attr(settings, :show_title, true) do
false -> false
_other -> true
end
end
defp normalize_pagination(nil, posts) do
total_items = length(posts)

View File

@@ -127,7 +127,7 @@ value PostContext {
excerpt: String?
author: String?
language: String?
show_title: Boolean -- Always true for post pages
show_title: Boolean -- True for post pages; in list/archive pages it is false when any of the post's categories has "show title" disabled (e.g. asides)
published_at: Timestamp
created_at: Timestamp
updated_at: Timestamp

View File

@@ -50,4 +50,22 @@ defmodule BDS.Generation.AsideArchiveRenderingTest do
assert category_html =~ "ASIDE BODY MARKER"
assert tag_html =~ "ASIDE BODY MARKER"
end
test "aside titles are hidden in category, tag, and date archives", %{
project: project,
temp_dir: temp_dir
} do
{:ok, _} = Generation.render_site_section(project.id, :category)
{:ok, _} = Generation.render_site_section(project.id, :tag)
{:ok, _} = Generation.render_site_section(project.id, :date)
year = Integer.to_string(DateTime.utc_now().year)
date_html = read_archive(temp_dir, [year])
category_html = read_archive(temp_dir, ["category", "aside"])
tag_html = read_archive(temp_dir, ["tag", "asides-tag"])
refute date_html =~ "Aside Title Marker"
refute category_html =~ "Aside Title Marker"
refute tag_html =~ "Aside Title Marker"
end
end