tpl: Fix the case for a shortcode in a nested folder only

Fixes #13605
This commit is contained in:
Bjørn Erik Pedersen
2025-04-14 11:41:56 +02:00
parent 8a2830f2dc
commit cf9e6904cc
3 changed files with 38 additions and 10 deletions

View File

@@ -122,6 +122,7 @@ func NewStore(opts StoreOptions, siteOpts SiteOptions) (*TemplateStore, error) {
treeMain: doctree.NewSimpleTree[map[nodeKey]*TemplInfo](),
treeShortcodes: doctree.NewSimpleTree[map[string]map[TemplateDescriptor]*TemplInfo](),
templatesByPath: maps.NewCache[string, *TemplInfo](),
shortcodesByName: maps.NewCache[string, *TemplInfo](),
cacheLookupPartials: maps.NewCache[string, *TemplInfo](),
// Note that the funcs passed below is just for name validation.
@@ -419,9 +420,10 @@ type TemplateStore struct {
siteOpts SiteOptions
htmlFormat output.Format
treeMain *doctree.SimpleTree[map[nodeKey]*TemplInfo]
treeShortcodes *doctree.SimpleTree[map[string]map[TemplateDescriptor]*TemplInfo]
templatesByPath *maps.Cache[string, *TemplInfo]
treeMain *doctree.SimpleTree[map[nodeKey]*TemplInfo]
treeShortcodes *doctree.SimpleTree[map[string]map[TemplateDescriptor]*TemplInfo]
templatesByPath *maps.Cache[string, *TemplInfo]
shortcodesByName *maps.Cache[string, *TemplInfo]
dh descriptorHandler
@@ -576,6 +578,15 @@ func (s *TemplateStore) LookupPartial(pth string) *TemplInfo {
return ti
}
func (s *TemplateStore) LookupShortcodeByName(name string) *TemplInfo {
name = strings.ToLower(name)
ti, _ := s.shortcodesByName.Get(name)
if ti == nil {
return nil
}
return ti
}
func (s *TemplateStore) LookupShortcode(q TemplateQuery) *TemplInfo {
q.init()
k1 := s.key(q.Path)
@@ -1039,6 +1050,7 @@ func (s *TemplateStore) insertShortcode(pi *paths.Path, fi hugofs.FileMetaInfo,
m1[d] = ti
s.shortcodesByName.Set(k2, ti)
s.setTemplateByPath(pi.Path(), ti)
if fi != nil {