From 99958f90fedec11d749a1397300860aa8e8459c2 Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Fri, 20 Mar 2020 09:37:21 +0100 Subject: Allow headless bundles to list pages via $page.Pages and $page.RegularPages Fixes #7075 --- hugolib/disableKinds_test.go | 55 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'hugolib/disableKinds_test.go') diff --git a/hugolib/disableKinds_test.go b/hugolib/disableKinds_test.go index b1c00b48e..9ac30442e 100644 --- a/hugolib/disableKinds_test.go +++ b/hugolib/disableKinds_test.go @@ -66,7 +66,26 @@ title: Headless headless: true --- -`) + +`, "headless-local/_index.md", ` +--- +title: Headless Local Lists +cascade: + _build: + render: false + list: local + publishResources: false +--- + +`, "headless-local/headless-local-page.md", "---\ntitle: Headless Local Page\n---", + "headless-local/sub/_index.md", ` +--- +title: Headless Local Lists Sub +--- + +`, "headless-local/sub/headless-local-sub-page.md", "---\ntitle: Headless Local Sub Page\n---", + ) + b.WithSourceFile("content/sect/headlessbundle/data.json", "DATA") b.WithSourceFile("content/sect/no-publishresources/data.json", "DATA") @@ -93,8 +112,11 @@ headless: true return nil } - getPageInPagePages := func(p page.Page, ref string) page.Page { - for _, pages := range []page.Pages{p.Pages(), p.RegularPages(), p.Sections()} { + getPageInPagePages := func(p page.Page, ref string, pageCollections ...page.Pages) page.Page { + if len(pageCollections) == 0 { + pageCollections = []page.Pages{p.Pages(), p.RegularPages(), p.RegularPagesRecursive(), p.Sections()} + } + for _, pages := range pageCollections { for _, p := range pages { if ref == p.(*pageState).sourceRef() { return p @@ -240,6 +262,33 @@ headless: true }) + c.Run("Build config, local list", func(c *qt.C) { + b := newSitesBuilder(c, disableKind) + b.Build(BuildCfg{}) + ref := "/headless-local" + sect := getPage(b, ref) + b.Assert(sect, qt.Not(qt.IsNil)) + b.Assert(getPageInSitePages(b, ref), qt.IsNil) + b.Assert(getPageInSitePages(b, ref+"/headless-local-page"), qt.IsNil) + for i, p := range sect.RegularPages() { + fmt.Println("REG", i, p.(*pageState).sourceRef()) + } + + localPageRef := ref + "/headless-local-page.md" + + b.Assert(getPageInPagePages(sect, localPageRef, sect.RegularPages()), qt.Not(qt.IsNil)) + b.Assert(getPageInPagePages(sect, localPageRef, sect.RegularPagesRecursive()), qt.Not(qt.IsNil)) + b.Assert(getPageInPagePages(sect, localPageRef, sect.Pages()), qt.Not(qt.IsNil)) + + ref = "/headless-local/sub" + + sect = getPage(b, ref) + b.Assert(sect, qt.Not(qt.IsNil)) + + localPageRef = ref + "/headless-local-sub-page.md" + b.Assert(getPageInPagePages(sect, localPageRef), qt.Not(qt.IsNil)) + }) + c.Run("Build config, no render", func(c *qt.C) { b := newSitesBuilder(c, disableKind) b.Build(BuildCfg{}) -- cgit v1.2.3