From 50646e4496d0888da9b3edef79c0f5cc456bb3f8 Mon Sep 17 00:00:00 2001
From: Patrick Kollitsch <davidsneighbourdev+gh@gmail.com>
Date: Tue, 17 Nov 2026 23:00:50 +0000
Subject: [PATCH] fix(layouts): allow hiding the section title on summary cards

---
 scripts/test-hugo-quickstart.ts      |   59 +++++++++++++++++++++++++++++
 layouts/summary.html                 |    5 ++
 layouts/_partials/func/IsShown.html  |   33 ++++++++++++++++
 layouts/_partials/func/ShowDate.html |   11 -----
 4 files changed, 96 insertions(+), 12 deletions(-)

diff --git a/layouts/_partials/func/IsShown.html b/layouts/_partials/func/IsShown.html
new file mode 100644
index 0000000..a58b171
--- /dev/null
+++ b/layouts/_partials/func/IsShown.html
@@ -0,0 +1,33 @@
+{{/*
+	IsShown
+
+	Decides whether an optional page element should be rendered.
+
+	The element is shown by default. It is hidden when the site sets
+	`ananke.pages.<key> = false`, unless a page opts back in with
+	`ananke.<key> = true` in its front matter. A page can also hide the
+	element with `ananke.<key> = false`. Sections can set the page value for
+	all of their pages with `cascade`.
+
+	@param page The page context.
+	@param key The name of the setting, for example `show_date`.
+	@return boolean True when the element should be displayed.
+
+*/}}
+{{- $site_value := "" -}}
+{{- with site.Params.ananke -}}
+	{{- with .pages -}}
+		{{- $site_value = index . $.key -}}
+	{{- end -}}
+{{- end -}}
+{{- $page_value := "" -}}
+{{- with .page.Params.ananke -}}
+	{{- $page_value = index . $.key -}}
+{{- end -}}
+{{- $show := not (eq false $site_value) -}}
+{{- if eq true $page_value -}}
+	{{- $show = true -}}
+{{- else if eq false $page_value -}}
+	{{- $show = false -}}
+{{- end -}}
+{{- return $show -}}
diff --git a/layouts/_partials/func/ShowDate.html b/layouts/_partials/func/ShowDate.html
index 9b784fa..5d57a99 100644
--- a/layouts/_partials/func/ShowDate.html
+++ b/layouts/_partials/func/ShowDate.html
@@ -18,14 +18,5 @@
 */}}
 {{ return and
 	(not .Date.IsZero)
-	(or
-		(and
-			(not (eq false site.Params.ananke.pages.show_date))
-			(not (eq false .Params.ananke.show_date))
-		)
-		(and
-			(eq false site.Params.ananke.pages.show_date)
-			(eq true .Params.ananke.show_date)
-		)
-	)
+	(partials.Include "func/IsShown.html" (dict "page" . "key" "show_date"))
 }}
diff --git a/layouts/summary.html b/layouts/summary.html
index 52b0517..7e55da8 100644
--- a/layouts/summary.html
+++ b/layouts/summary.html
@@ -1,7 +1,10 @@
 {{ $show_date := partials.Include "func/ShowDate.html" . }}
+{{ $show_section_title := partials.Include "func/IsShown.html" (dict "page" . "key" "show_section_title") }}
 <div class="w-100 mb4 nested-copy-line-height relative bg-white">
   <div class="mb3 pa4 gray overflow-hidden bg-white">
-    {{with .CurrentSection.Title }}<span class="f6 db">{{ . }}</span>{{end}}
+    {{ if $show_section_title }}
+      {{ with .CurrentSection.Title }}<span class="f6 db">{{ . }}</span>{{ end }}
+    {{ end }}
     {{ if $show_date }}
       <time class="f6 db" {{ fmt.Printf `datetime="%s"` (.Date.Format "2006-01-02T15:04:05Z07:00") | safe.HTMLAttr }}>
         {{- .Date | time.Format (compare.Default "January 2, 2006" .Site.Params.date_format) -}}
diff --git a/scripts/test-hugo-quickstart.ts b/scripts/test-hugo-quickstart.ts
index 396fd7c..024f052 100644
--- a/scripts/test-hugo-quickstart.ts
+++ b/scripts/test-hugo-quickstart.ts
@@ -820,6 +820,12 @@
 const SUMMARY_CARD_DATE_MARKER = "datetime=";
 
 /**
+ * Markup emitted by `summary.html` when the section title of a card is
+ * rendered for the `cards` fixture section.
+ */
+const SUMMARY_CARD_SECTION_MARKER = '<span class="f6 db">Cards</span>';
+
+/**
  * Create a content section whose list page exercises both the image and the
  * date behaviour of summary cards: one page has a featured image, the other
  * does not, and both carry an explicit date.
@@ -870,11 +876,12 @@
 function assertListCardSummaries(
   listHtml: string,
   label: string,
-  expectations: { images: boolean; dates: boolean },
+  expectations: { images: boolean; dates: boolean; sectionTitles?: boolean },
 ): void {
   const failures: string[] = [];
   const hasImage = listHtml.includes(LIST_CARD_IMAGE_MARKER);
   const hasDate = listHtml.includes(SUMMARY_CARD_DATE_MARKER);
+  const hasSectionTitle = listHtml.includes(SUMMARY_CARD_SECTION_MARKER);
 
   if (expectations.images && !hasImage) {
     failures.push(
@@ -900,6 +907,18 @@
     );
   }
 
+  if (expectations.sectionTitles === true && !hasSectionTitle) {
+    failures.push(
+      "- expected summary card section titles but none were rendered by default",
+    );
+  }
+
+  if (expectations.sectionTitles === false && hasSectionTitle) {
+    failures.push(
+      "- summary card section titles were rendered when 'ananke.pages.show_section_title' was false",
+    );
+  }
+
   if (failures.length > 0) {
     throw new Error(
       [
@@ -1368,6 +1387,7 @@
     assertListCardSummaries(await readTextFile(cardsListPath), "defaults", {
       images: false,
       dates: true,
+      sectionTitles: true,
     });
 
     // Opt in to image cards and disable summary dates: images appear and the
@@ -1404,6 +1424,43 @@
 
     console.log("[OK ] List page image cards and summary dates (issue #217)");
 
+    console.log(
+      "\n[RUN] Hide summary card dates and section titles (issue #1109)",
+    );
+    await writeTextFile(
+      configPath,
+      [
+        "baseURL = 'https://example.com/'",
+        "title = 'Ananke Test Quickstart'",
+        `theme = '${options.themeName}'`,
+        "[params.ananke.pages]",
+        "show_date = false",
+        "show_section_title = false",
+        "",
+      ].join("\n"),
+    );
+    const cardsPlainBuildStep: StepDefinition = {
+      name: "Build site with summary dates and section titles disabled",
+      command: "hugo",
+      args: [],
+      cwd: projectRoot,
+      expectedFiles: ["public/cards/index.html"],
+    };
+    const cardsPlainBuildReport = await executeHugoBuildStep(
+      cardsPlainBuildStep,
+      projectRoot,
+    );
+    reports.push(cardsPlainBuildReport);
+    assertListCardSummaries(
+      await readTextFile(cardsListPath),
+      "dates and section titles disabled",
+      { images: false, dates: false, sectionTitles: false },
+    );
+
+    console.log(
+      "[OK ] Hide summary card dates and section titles (issue #1109)",
+    );
+
     console.log("\nResult: PASS");
 
     if (options.keepOnSuccess) {

--
Gitblit v1.10.0