Fix it so not all bundled resources are removed when one translation is drafted

Fixes #12105
This commit is contained in:
Bjørn Erik Pedersen 2024-02-22 15:06:42 +01:00
parent f5fd7ec8cc
commit db3bb623d4
3 changed files with 48 additions and 8 deletions

View file

@ -221,10 +221,22 @@ func (t pageTrees) Shape(d, v int) *pageTrees {
t.treePages = t.treePages.Shape(d, v) t.treePages = t.treePages.Shape(d, v)
t.treeResources = t.treeResources.Shape(d, v) t.treeResources = t.treeResources.Shape(d, v)
t.treeTaxonomyEntries = t.treeTaxonomyEntries.Shape(d, v) t.treeTaxonomyEntries = t.treeTaxonomyEntries.Shape(d, v)
t.createMutableTrees()
return &t return &t
} }
func (t *pageTrees) createMutableTrees() {
t.treePagesResources = doctree.WalkableTrees[contentNodeI]{
t.treePages,
t.treeResources,
}
t.resourceTrees = doctree.MutableTrees{
t.treeResources,
}
}
var ( var (
_ resource.Identifier = pageMapQueryPagesInSection{} _ resource.Identifier = pageMapQueryPagesInSection{}
_ resource.Identifier = pageMapQueryPagesBelowPath{} _ resource.Identifier = pageMapQueryPagesBelowPath{}
@ -676,9 +688,15 @@ func (s *contentNodeShifter) Delete(n contentNodeI, dimension doctree.Dimension)
} }
return wasDeleted, isEmpty return wasDeleted, isEmpty
case *resourceSource: case *resourceSource:
if lidx > 0 {
return false, false
}
resource.MarkStale(v) resource.MarkStale(v)
return true, true return true, true
case *pageState: case *pageState:
if lidx > 0 {
return false, false
}
resource.MarkStale(v) resource.MarkStale(v)
return true, true return true, true
default: default:
@ -1694,6 +1712,9 @@ func (sa *sitePagesAssembler) removeShouldNotBuild() error {
return err return err
} }
if len(keys) == 0 {
return nil
}
sa.pageMap.DeletePageAndResourcesBelow(keys...) sa.pageMap.DeletePageAndResourcesBelow(keys...)
return nil return nil

View file

@ -893,3 +893,29 @@ Match: {{ range .Resources.Match "f1.en.*" }}{{ .Name }}: {{ .Content }}|{{ end
b.AssertFileContent("public/mybundle/index.html", "GetMatch: f1.txt: F1.|", "Match: f1.txt: F1.|") b.AssertFileContent("public/mybundle/index.html", "GetMatch: f1.txt: F1.|", "Match: f1.txt: F1.|")
} }
func TestBundleResourcesWhenLanguageVariantIsDraft(t *testing.T) {
files := `
-- hugo.toml --
baseURL = "https://example.com"
defaultContentLanguage = "en"
[languages]
[languages.en]
weight = 1
[languages.nn]
weight = 2
-- content/mybundle/index.en.md --
-- content/mybundle/index.nn.md --
---
draft: true
---
-- content/mybundle/f1.en.txt --
F1.
-- layouts/_default/single.html --
GetMatch: {{ with .Resources.GetMatch "f1.*" }}{{ .Name }}: {{ .Content }}|{{ end }}$
`
b := Test(t, files)
b.AssertFileContent("public/mybundle/index.html", "GetMatch: f1.txt: F1.|")
}

View file

@ -165,14 +165,7 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
treeTaxonomyEntries: doctree.NewTreeShiftTree[*weightedContentNode](doctree.DimensionLanguage.Index(), len(confm.Languages)), treeTaxonomyEntries: doctree.NewTreeShiftTree[*weightedContentNode](doctree.DimensionLanguage.Index(), len(confm.Languages)),
} }
pageTrees.treePagesResources = doctree.WalkableTrees[contentNodeI]{ pageTrees.createMutableTrees()
pageTrees.treePages,
pageTrees.treeResources,
}
pageTrees.resourceTrees = doctree.MutableTrees{
pageTrees.treeResources,
}
for i, confp := range confm.ConfigLangs() { for i, confp := range confm.ConfigLangs() {
language := confp.Language() language := confp.Language()