From 9bdedb251c7cd8f8af800c7d9914cf84292c5c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 19 Feb 2020 17:37:20 +0100 Subject: [PATCH] Fix lazy publishing with publishResources=false Fixes #6914 --- hugolib/content_map_page.go | 1 + hugolib/disableKinds_test.go | 30 ++++++++++++++++++++++++++++++ hugolib/page.go | 4 +++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index 5075095ea..ca84ee873 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -262,6 +262,7 @@ func (m *pageMap) newResource(fim hugofs.FileMetaInfo, owner *pageState) (resour FileInfo: fim, RelTargetFilename: target, TargetBasePaths: targetBasePaths, + LazyPublish: !owner.m.buildConfig.PublishResources, }) } diff --git a/hugolib/disableKinds_test.go b/hugolib/disableKinds_test.go index e814f4a5a..3d78e29f3 100644 --- a/hugolib/disableKinds_test.go +++ b/hugolib/disableKinds_test.go @@ -32,6 +32,7 @@ disableKinds = [%q] `, disableKind) b := newTestSitesBuilder(c) + b.WithTemplatesAdded("_default/single.html", `single`) b.WithConfigFile("toml", config).WithContent("sect/page.md", ` --- title: Page @@ -281,3 +282,32 @@ home = [ "HTML", "RSS" ] b.Assert(b.CheckExists("public/index.xml"), qt.Equals, false) } + +func TestBundleNoPublishResources(t *testing.T) { + b := newTestSitesBuilder(t) + b.WithTemplates("index.html", ` +{{ $bundle := site.GetPage "section/bundle-false" }} +{{ $data1 := $bundle.Resources.GetMatch "data1*" }} +Data1: {{ $data1.RelPermalink }} + +`) + + b.WithContent("section/bundle-false/index.md", `---\ntitle: BundleFalse +_build: + publishResources: false +---`, + "section/bundle-false/data1.json", "Some data1", + "section/bundle-false/data2.json", "Some data2", + ) + + b.WithContent("section/bundle-true/index.md", `---\ntitle: BundleTrue +---`, + "section/bundle-true/data3.json", "Some data 3", + ) + + b.Build(BuildCfg{}) + b.AssertFileContent("public/index.html", `Data1: /section/bundle-false/data1.json`) + b.AssertFileContent("public/section/bundle-false/data1.json", `Some data1`) + b.Assert(b.CheckExists("public/section/bundle-false/data2.json"), qt.Equals, false) + b.AssertFileContent("public/section/bundle-true/data3.json", `Some data 3`) +} diff --git a/hugolib/page.go b/hugolib/page.go index 12129d4ad..e032f5adc 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -258,7 +258,9 @@ func (p *pageState) sortResources() { return page.DefaultPageSort(p1, p2) } - return ri.RelPermalink() < rj.RelPermalink() + // Make sure not to use RelPermalink or any of the other methods that + // trigger lazy publishing. + return ri.Name() < rj.Name() }) }