From bb80fff69ad3f2ddff23819bf6eb6f4b8512dc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 29 Nov 2019 11:12:54 +0100 Subject: [PATCH] Fix headless regression Fixes #6552 --- hugolib/pagebundler_test.go | 37 +++++++++++++++++++++++++++++++++++++ hugolib/pages_map.go | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/hugolib/pagebundler_test.go b/hugolib/pagebundler_test.go index c76cc6a77..da7427d7e 100644 --- a/hugolib/pagebundler_test.go +++ b/hugolib/pagebundler_test.go @@ -587,6 +587,43 @@ HEADLESS {{< myShort >}} } +func TestPageBundlerHeadlessIssue6552(t *testing.T) { + t.Parallel() + + b := newTestSitesBuilder(t) + b.WithContent("headless/h1/index.md", ` +--- +title: My Headless Bundle1 +headless: true +--- +`, "headless/h1/p1.md", ` +--- +title: P1 +--- +`, "headless/h2/index.md", ` +--- +title: My Headless Bundle2 +headless: true +--- +`) + + b.WithTemplatesAdded("index.html", ` +{{ $headless1 := .Site.GetPage "headless/h1" }} +{{ $headless2 := .Site.GetPage "headless/h2" }} + +HEADLESS1: {{ $headless1.Title }}|{{ $headless1.RelPermalink }}|{{ len $headless1.Resources }}| +HEADLESS2: {{ $headless2.Title }}{{ $headless2.RelPermalink }}|{{ len $headless2.Resources }}| + +`) + + b.Build(BuildCfg{}) + + b.AssertFileContent("public/index.html", ` +HEADLESS1: My Headless Bundle1||1| +HEADLESS2: My Headless Bundle2|0| +`) +} + func TestMultiSiteBundles(t *testing.T) { c := qt.New(t) b := newTestSitesBuilder(t) diff --git a/hugolib/pages_map.go b/hugolib/pages_map.go index 7c53aaf3f..57b50cdee 100644 --- a/hugolib/pages_map.go +++ b/hugolib/pages_map.go @@ -439,7 +439,7 @@ type pagesMapBucket struct { } func (b *pagesMapBucket) isEmpty() bool { - return len(b.pages) == 0 && len(b.bucketSections) == 0 + return len(b.pages) == 0 && len(b.headlessPages) == 0 && len(b.bucketSections) == 0 } func (b *pagesMapBucket) getPages() page.Pages {