From f6db2ffa757d50f3167846bef57a9b9afd796fd1 Mon Sep 17 00:00:00 2001
From: Patrick Kollitsch <davidsneighbourdev+gh@gmail.com>
Date: Sat, 21 Nov 2026 08:13:07 +0000
Subject: [PATCH] fix(layouts): skip the home introduction when it has no content
---
layouts/home.html | 10 +++++++---
tests/fixtures/home-content/filled/content/_index.md | 5 +++++
tests/fixtures/home-content/home-content.test.mjs | 26 ++++++++++++++++++++++++++
tests/fixtures/home-content/empty/content/post/first.md | 5 +++++
tests/fixtures/home-content/empty/content/_index.md | 4 ++++
tests/fixtures/home-content/filled/hugo.toml | 2 ++
tests/fixtures/home-content/filled/content/post/first.md | 5 +++++
tests/fixtures/home-content/empty/hugo.toml | 2 ++
8 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/layouts/home.html b/layouts/home.html
index 65798bd..8722663 100644
--- a/layouts/home.html
+++ b/layouts/home.html
@@ -8,9 +8,13 @@
{{- $text_alignment = "tr-l" -}}
{{- end -}}
- <article class="cf ph3 ph5-l pv3 pv4-l f4 {{ $text_alignment }} center measure-wide lh-copy nested-links {{ $.Param "text_color" | compare.Default "mid-gray" }}">
- {{ .Content }}
- </article>
+ {{- /* Render the introduction only when the home page has content, so an
+ empty home page has no blank space above the recent posts. */ -}}
+ {{ with .Content }}
+ <article class="cf ph3 ph5-l pv3 pv4-l f4 {{ $text_alignment }} center measure-wide lh-copy nested-links {{ $.Param "text_color" | compare.Default "mid-gray" }}">
+ {{ . }}
+ </article>
+ {{ end }}
{{/* Define a section to pull recent posts from. For Hugo 0.20 this will default to the section with the most number of pages. */}}
{{ $mainSections := site.Params.mainSections | compare.Default (collections.Slice "post") }}
diff --git a/tests/fixtures/home-content/empty/content/_index.md b/tests/fixtures/home-content/empty/content/_index.md
new file mode 100644
index 0000000..14a4dce
--- /dev/null
+++ b/tests/fixtures/home-content/empty/content/_index.md
@@ -0,0 +1,4 @@
+---
+title: Home
+---
+
diff --git a/tests/fixtures/home-content/empty/content/post/first.md b/tests/fixtures/home-content/empty/content/post/first.md
new file mode 100644
index 0000000..8c4f251
--- /dev/null
+++ b/tests/fixtures/home-content/empty/content/post/first.md
@@ -0,0 +1,5 @@
+---
+title: First post
+---
+
+Body.
diff --git a/tests/fixtures/home-content/empty/hugo.toml b/tests/fixtures/home-content/empty/hugo.toml
new file mode 100644
index 0000000..11d4ccb
--- /dev/null
+++ b/tests/fixtures/home-content/empty/hugo.toml
@@ -0,0 +1,2 @@
+title = "Home content fixture"
+theme = "ananke"
diff --git a/tests/fixtures/home-content/filled/content/_index.md b/tests/fixtures/home-content/filled/content/_index.md
new file mode 100644
index 0000000..bc1e760
--- /dev/null
+++ b/tests/fixtures/home-content/filled/content/_index.md
@@ -0,0 +1,5 @@
+---
+title: Home
+---
+
+Home introduction.
diff --git a/tests/fixtures/home-content/filled/content/post/first.md b/tests/fixtures/home-content/filled/content/post/first.md
new file mode 100644
index 0000000..8c4f251
--- /dev/null
+++ b/tests/fixtures/home-content/filled/content/post/first.md
@@ -0,0 +1,5 @@
+---
+title: First post
+---
+
+Body.
diff --git a/tests/fixtures/home-content/filled/hugo.toml b/tests/fixtures/home-content/filled/hugo.toml
new file mode 100644
index 0000000..11d4ccb
--- /dev/null
+++ b/tests/fixtures/home-content/filled/hugo.toml
@@ -0,0 +1,2 @@
+title = "Home content fixture"
+theme = "ananke"
diff --git a/tests/fixtures/home-content/home-content.test.mjs b/tests/fixtures/home-content/home-content.test.mjs
new file mode 100644
index 0000000..c2239fa
--- /dev/null
+++ b/tests/fixtures/home-content/home-content.test.mjs
@@ -0,0 +1,26 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { dirname, join } from "node:path";
+import { test } from "node:test";
+import { fileURLToPath } from "node:url";
+import { load } from "cheerio";
+import { buildFixtureSite } from "../../support/prepare-site.mjs";
+
+const root = dirname(fileURLToPath(import.meta.url));
+
+function home(name) {
+ const output = buildFixtureSite({ source: join(root, name) });
+ return load(readFileSync(join(output, "index.html"), "utf8"));
+}
+
+test("home page without content renders no introduction article (#663)", () => {
+ const $ = home("empty");
+ assert.equal($("main > article").length, 0);
+ assert.equal($("main a[href$='/post/first/']").length > 0, true);
+});
+
+test("home page with content renders the introduction article (#663)", () => {
+ const $ = home("filled");
+ assert.equal($("main > article").length, 1);
+ assert.equal($("main > article").text().trim(), "Home introduction.");
+});
--
Gitblit v1.10.0