mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
Fix some change detection issues on server reloads
* Fix change detection when .GetPage/site.GetPage is used from shortcode * Fix stale content for GetPage results with short name lookups on server reloads Fixes #7623 Fixes #7624 Fixes #7625
This commit is contained in:
@@ -95,21 +95,23 @@ func newContentMap(cfg contentMapConfig) *contentMap {
|
||||
|
||||
m.pageReverseIndex = &contentTreeReverseIndex{
|
||||
t: []*contentTree{m.pages, m.sections, m.taxonomies},
|
||||
initFn: func(t *contentTree, m map[interface{}]*contentNode) {
|
||||
t.Walk(func(s string, v interface{}) bool {
|
||||
n := v.(*contentNode)
|
||||
if n.p != nil && !n.p.File().IsZero() {
|
||||
meta := n.p.File().FileInfo().Meta()
|
||||
if meta.Path() != meta.PathFile() {
|
||||
// Keep track of the original mount source.
|
||||
mountKey := filepath.ToSlash(filepath.Join(meta.Module(), meta.PathFile()))
|
||||
addToReverseMap(mountKey, n, m)
|
||||
contentTreeReverseIndexMap: &contentTreeReverseIndexMap{
|
||||
initFn: func(t *contentTree, m map[interface{}]*contentNode) {
|
||||
t.Walk(func(s string, v interface{}) bool {
|
||||
n := v.(*contentNode)
|
||||
if n.p != nil && !n.p.File().IsZero() {
|
||||
meta := n.p.File().FileInfo().Meta()
|
||||
if meta.Path() != meta.PathFile() {
|
||||
// Keep track of the original mount source.
|
||||
mountKey := filepath.ToSlash(filepath.Join(meta.Module(), meta.PathFile()))
|
||||
addToReverseMap(mountKey, n, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
k := strings.TrimPrefix(strings.TrimSuffix(path.Base(s), cmLeafSeparator), cmBranchSeparator)
|
||||
addToReverseMap(k, n, m)
|
||||
return false
|
||||
})
|
||||
k := strings.TrimPrefix(strings.TrimSuffix(path.Base(s), cmLeafSeparator), cmBranchSeparator)
|
||||
addToReverseMap(k, n, m)
|
||||
return false
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1030,12 +1032,21 @@ func (c *contentTreeRef) getSections() page.Pages {
|
||||
|
||||
type contentTreeReverseIndex struct {
|
||||
t []*contentTree
|
||||
m map[interface{}]*contentNode
|
||||
*contentTreeReverseIndexMap
|
||||
}
|
||||
|
||||
type contentTreeReverseIndexMap struct {
|
||||
m map[interface{}]*contentNode
|
||||
init sync.Once
|
||||
initFn func(*contentTree, map[interface{}]*contentNode)
|
||||
}
|
||||
|
||||
func (c *contentTreeReverseIndex) Reset() {
|
||||
c.contentTreeReverseIndexMap = &contentTreeReverseIndexMap{
|
||||
initFn: c.initFn,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *contentTreeReverseIndex) Get(key interface{}) *contentNode {
|
||||
c.init.Do(func() {
|
||||
c.m = make(map[interface{}]*contentNode)
|
||||
|
Reference in New Issue
Block a user