| layouts/home.html | ●●●●● patch | view | raw | blame | history | |
| tests/fixtures/home-content/empty/content/_index.md | ●●●●● patch | view | raw | blame | history | |
| tests/fixtures/home-content/empty/content/post/first.md | ●●●●● patch | view | raw | blame | history | |
| tests/fixtures/home-content/empty/hugo.toml | ●●●●● patch | view | raw | blame | history | |
| tests/fixtures/home-content/filled/content/_index.md | ●●●●● patch | view | raw | blame | history | |
| tests/fixtures/home-content/filled/content/post/first.md | ●●●●● patch | view | raw | blame | history | |
| tests/fixtures/home-content/filled/hugo.toml | ●●●●● patch | view | raw | blame | history | |
| tests/fixtures/home-content/home-content.test.mjs | ●●●●● patch | view | raw | blame | history |
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") }} tests/fixtures/home-content/empty/content/_index.md
New file @@ -0,0 +1,4 @@ --- title: Home --- tests/fixtures/home-content/empty/content/post/first.md
New file @@ -0,0 +1,5 @@ --- title: First post --- Body. tests/fixtures/home-content/empty/hugo.toml
New file @@ -0,0 +1,2 @@ title = "Home content fixture" theme = "ananke" tests/fixtures/home-content/filled/content/_index.md
New file @@ -0,0 +1,5 @@ --- title: Home --- Home introduction. tests/fixtures/home-content/filled/content/post/first.md
New file @@ -0,0 +1,5 @@ --- title: First post --- Body. tests/fixtures/home-content/filled/hugo.toml
New file @@ -0,0 +1,2 @@ title = "Home content fixture" theme = "ananke" tests/fixtures/home-content/home-content.test.mjs
New file @@ -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."); });