mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
@@ -677,13 +677,7 @@ Loop:
|
|||||||
|
|
||||||
// Used to check if the template expects inner content,
|
// Used to check if the template expects inner content,
|
||||||
// so just pick one arbitrarily with the same name.
|
// so just pick one arbitrarily with the same name.
|
||||||
q := tplimpl.TemplateQuery{
|
templ := s.s.TemplateStore.LookupShortcodeByName(sc.name)
|
||||||
Path: "",
|
|
||||||
Name: sc.name,
|
|
||||||
Category: tplimpl.CategoryShortcode,
|
|
||||||
Consider: nil,
|
|
||||||
}
|
|
||||||
templ := s.s.TemplateStore.LookupShortcode(q)
|
|
||||||
if templ == nil {
|
if templ == nil {
|
||||||
return nil, fmt.Errorf("%s: template for shortcode %q not found", errorPrefix, sc.name)
|
return nil, fmt.Errorf("%s: template for shortcode %q not found", errorPrefix, sc.name)
|
||||||
}
|
}
|
||||||
|
@@ -122,6 +122,7 @@ func NewStore(opts StoreOptions, siteOpts SiteOptions) (*TemplateStore, error) {
|
|||||||
treeMain: doctree.NewSimpleTree[map[nodeKey]*TemplInfo](),
|
treeMain: doctree.NewSimpleTree[map[nodeKey]*TemplInfo](),
|
||||||
treeShortcodes: doctree.NewSimpleTree[map[string]map[TemplateDescriptor]*TemplInfo](),
|
treeShortcodes: doctree.NewSimpleTree[map[string]map[TemplateDescriptor]*TemplInfo](),
|
||||||
templatesByPath: maps.NewCache[string, *TemplInfo](),
|
templatesByPath: maps.NewCache[string, *TemplInfo](),
|
||||||
|
shortcodesByName: maps.NewCache[string, *TemplInfo](),
|
||||||
cacheLookupPartials: maps.NewCache[string, *TemplInfo](),
|
cacheLookupPartials: maps.NewCache[string, *TemplInfo](),
|
||||||
|
|
||||||
// Note that the funcs passed below is just for name validation.
|
// Note that the funcs passed below is just for name validation.
|
||||||
@@ -419,9 +420,10 @@ type TemplateStore struct {
|
|||||||
siteOpts SiteOptions
|
siteOpts SiteOptions
|
||||||
htmlFormat output.Format
|
htmlFormat output.Format
|
||||||
|
|
||||||
treeMain *doctree.SimpleTree[map[nodeKey]*TemplInfo]
|
treeMain *doctree.SimpleTree[map[nodeKey]*TemplInfo]
|
||||||
treeShortcodes *doctree.SimpleTree[map[string]map[TemplateDescriptor]*TemplInfo]
|
treeShortcodes *doctree.SimpleTree[map[string]map[TemplateDescriptor]*TemplInfo]
|
||||||
templatesByPath *maps.Cache[string, *TemplInfo]
|
templatesByPath *maps.Cache[string, *TemplInfo]
|
||||||
|
shortcodesByName *maps.Cache[string, *TemplInfo]
|
||||||
|
|
||||||
dh descriptorHandler
|
dh descriptorHandler
|
||||||
|
|
||||||
@@ -576,6 +578,15 @@ func (s *TemplateStore) LookupPartial(pth string) *TemplInfo {
|
|||||||
return ti
|
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 {
|
func (s *TemplateStore) LookupShortcode(q TemplateQuery) *TemplInfo {
|
||||||
q.init()
|
q.init()
|
||||||
k1 := s.key(q.Path)
|
k1 := s.key(q.Path)
|
||||||
@@ -1039,6 +1050,7 @@ func (s *TemplateStore) insertShortcode(pi *paths.Path, fi hugofs.FileMetaInfo,
|
|||||||
|
|
||||||
m1[d] = ti
|
m1[d] = ti
|
||||||
|
|
||||||
|
s.shortcodesByName.Set(k2, ti)
|
||||||
s.setTemplateByPath(pi.Path(), ti)
|
s.setTemplateByPath(pi.Path(), ti)
|
||||||
|
|
||||||
if fi != nil {
|
if fi != nil {
|
||||||
|
@@ -1127,6 +1127,28 @@ single.html
|
|||||||
b.AssertFileContent("public/s3/index.html", "single.html") // fail
|
b.AssertFileContent("public/s3/index.html", "single.html") // fail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssue13605(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
|
||||||
|
-- content/s1/p1.md --
|
||||||
|
---
|
||||||
|
title: p1
|
||||||
|
---
|
||||||
|
{{< sc >}}
|
||||||
|
-- layouts/s1/_shortcodes/sc.html --
|
||||||
|
layouts/s1/_shortcodes/sc.html
|
||||||
|
-- layouts/single.html --
|
||||||
|
{{ .Content }}
|
||||||
|
`
|
||||||
|
|
||||||
|
b := hugolib.Test(t, files)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/s1/p1/index.html", "layouts/s1/_shortcodes/sc.html")
|
||||||
|
}
|
||||||
|
|
||||||
func TestSkipDotFiles(t *testing.T) {
|
func TestSkipDotFiles(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user