From cf1d4bd46f50316d2afa0b3b93ed99a251fd2be9 Mon Sep 17 00:00:00 2001 From: Chili Palmer Date: Sun, 5 Jul 2026 12:39:59 +0200 Subject: [PATCH] fix: issue #6 had missing title suppression --- lib/bds/rendering/list_archive.ex | 43 +++++++++++++++++-- specs/template_context.allium | 2 +- .../aside_archive_rendering_test.exs | 18 ++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/lib/bds/rendering/list_archive.ex b/lib/bds/rendering/list_archive.ex index 23f38aa..8434262 100644 --- a/lib/bds/rendering/list_archive.ex +++ b/lib/bds/rendering/list_archive.ex @@ -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) diff --git a/specs/template_context.allium b/specs/template_context.allium index 9f640e0..61c55fb 100644 --- a/specs/template_context.allium +++ b/specs/template_context.allium @@ -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 diff --git a/test/bds/generation/aside_archive_rendering_test.exs b/test/bds/generation/aside_archive_rendering_test.exs index 8679673..249d313 100644 --- a/test/bds/generation/aside_archive_rendering_test.exs +++ b/test/bds/generation/aside_archive_rendering_test.exs @@ -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