Skip to content

Commit a1cb15e

Browse files
committed
Fix it so the owning taxonomy gets rerendered in server when new tags are added
Updates #13648
1 parent 673a4d0 commit a1cb15e

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

hugolib/content_map_page.go

+11
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,7 @@ func (h *HugoSites) resolveAndResetDependententPageOutputs(ctx context.Context,
13301330
// This needs no reset, so no need to check it.
13311331
return nil
13321332
}
1333+
13331334
// First check the top level dependency manager.
13341335
for _, id := range changes {
13351336
checkedCounter.Add(1)
@@ -1645,6 +1646,8 @@ func (sa *sitePagesAssembler) assembleTermsAndTranslations() error {
16451646
views = sa.pageMap.cfg.taxonomyConfig.views
16461647
)
16471648

1649+
rebuild := sa.s.h.isRebuild()
1650+
16481651
lockType := doctree.LockTypeWrite
16491652
w := &doctree.NodeShiftTreeWalker[contentNodeI]{
16501653
Tree: pages,
@@ -1677,6 +1680,14 @@ func (sa *sitePagesAssembler) assembleTermsAndTranslations() error {
16771680
pi := sa.Site.Conf.PathParser().Parse(files.ComponentFolderContent, viewTermKey+"/_index.md")
16781681
term := pages.Get(pi.Base())
16791682
if term == nil {
1683+
if rebuild {
1684+
// A new tag was added in server mode.
1685+
taxonomy := pages.Get(viewName.pluralTreeKey)
1686+
if taxonomy != nil {
1687+
sa.assembleChanges.Add(taxonomy.GetIdentity())
1688+
}
1689+
}
1690+
16801691
m := &pageMeta{
16811692
term: v,
16821693
singular: viewName.singular,

hugolib/hugo_sites_build.go

+8
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,14 @@ func (h *HugoSites) assemble(ctx context.Context, l logg.LevelLogger, bcfg *Buil
324324
}
325325
}
326326

327+
// Handle new terms from assemblePagesStep2.
328+
changes = bcfg.WhatChanged.Drain()
329+
if len(changes) > 0 {
330+
if err := h.resolveAndClearStateForIdentities(ctx, l, nil, changes); err != nil {
331+
return err
332+
}
333+
}
334+
327335
h.renderFormats = output.Formats{}
328336
for _, s := range h.Sites {
329337
s.s.initRenderFormats()

hugolib/rebuild_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -1865,3 +1865,30 @@ p1-content|
18651865
b.EditFileReplaceAll("content/p1/index.md", "p1-content", "p1-content-foo").Build()
18661866
b.AssertFileContent("public/p1/index.html", "p1-content-foo")
18671867
}
1868+
1869+
func TestRebuildEditTagIssue13648(t *testing.T) {
1870+
t.Parallel()
1871+
1872+
files := `
1873+
-- hugo.toml --
1874+
baseURL = "https://example.com"
1875+
disableLiveReload = true
1876+
-- layouts/all.html --
1877+
All. {{ range .Pages }}{{ .Title }}|{{ end }}
1878+
-- content/p1.md --
1879+
---
1880+
title: "P1"
1881+
tags: ["tag1"]
1882+
---
1883+
1884+
`
1885+
b := TestRunning(t, files)
1886+
1887+
b.AssertFileContent("public/tags/index.html", "All. Tag1|")
1888+
b.EditFileReplaceAll("content/p1.md", "tag1", "tag2").Build()
1889+
1890+
// Note that the below is still not correct, as this is effectively a rename, and
1891+
// Tag2 should be removed from the list.
1892+
// But that is a harder problem to tackle.
1893+
b.AssertFileContent("public/tags/index.html", "All. Tag1|Tag2|")
1894+
}

0 commit comments

Comments
 (0)