diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-02-20 13:40:16 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-02-20 13:40:16 +0100 |
commit | a70bbd0696df3b0a6889650e48a07f8223151da4 (patch) | |
tree | 3f0d314e25f41039feb8ea3669bce0aaa9d5aac7 | |
parent | 24afe2b822b458bae8f2ca9a9e095339f820a2f6 (diff) |
hugolib: Fix deletion of orphaned sections
Avoid deleting inside the recursive walk.
Fixes #6920
-rw-r--r-- | hugolib/content_map.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/hugolib/content_map.go b/hugolib/content_map.go index 279c8e43a..efa2254b2 100644 --- a/hugolib/content_map.go +++ b/hugolib/content_map.go @@ -596,6 +596,7 @@ func (m *contentMap) deleteBundleMatching(matches func(b *contentNode) bool) { // Deletes any empty root section that's not backed by a content file. func (m *contentMap) deleteOrphanSections() { + var sectionsToDelete []string m.sections.Walk(func(s string, v interface{}) bool { n := v.(*contentNode) @@ -612,11 +613,15 @@ func (m *contentMap) deleteOrphanSections() { prefixBundle := s + cmBranchSeparator if !(m.sections.hasPrefix(s+"/") || m.pages.hasPrefix(prefixBundle) || m.resources.hasPrefix(prefixBundle)) { - m.sections.Delete(s) + sectionsToDelete = append(sectionsToDelete, s) } return false }) + + for _, s := range sectionsToDelete { + m.sections.Delete(s) + } } func (m *contentMap) deletePage(s string) { |