mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +02:00
tpl: Fix language handling in partials
We now use the same code path for all templates re this. Fixes #13612
This commit is contained in:
@@ -564,14 +564,21 @@ func (s *TemplateStore) LookupPagesLayout(q TemplateQuery) *TemplInfo {
|
||||
|
||||
func (s *TemplateStore) LookupPartial(pth string) *TemplInfo {
|
||||
ti, _ := s.cacheLookupPartials.GetOrCreate(pth, func() (*TemplInfo, error) {
|
||||
d := s.templateDescriptorFromPath(pth)
|
||||
desc := d.Desc
|
||||
if desc.LayoutFromTemplate != "" {
|
||||
panic("shortcode template descriptor must not have a layout")
|
||||
pi := s.opts.PathParser.Parse(files.ComponentFolderLayouts, pth).ForType(paths.TypePartial)
|
||||
k1, _, _, desc, err := s.toKeyCategoryAndDescriptor(pi)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if desc.OutputFormat == "" && desc.MediaType == "" {
|
||||
// Assume HTML.
|
||||
desc.OutputFormat = s.htmlFormat.Name
|
||||
desc.MediaType = s.htmlFormat.MediaType.Type
|
||||
desc.IsPlainText = s.htmlFormat.IsPlainText
|
||||
}
|
||||
|
||||
best := s.getBest()
|
||||
defer s.putBest(best)
|
||||
s.findBestMatchGet(s.key(path.Join(containerPartials, d.Path)), CategoryPartial, nil, desc, best)
|
||||
s.findBestMatchGet(s.key(path.Join(containerPartials, k1)), CategoryPartial, nil, desc, best)
|
||||
return best.templ, nil
|
||||
})
|
||||
|
||||
@@ -1486,43 +1493,6 @@ type PathTemplateDescriptor struct {
|
||||
Desc TemplateDescriptor
|
||||
}
|
||||
|
||||
// templateDescriptorFromPath returns a template descriptor from the given path.
|
||||
// This is currently used in partial lookups only.
|
||||
func (s *TemplateStore) templateDescriptorFromPath(pth string) PathTemplateDescriptor {
|
||||
var (
|
||||
mt media.Type
|
||||
of output.Format
|
||||
)
|
||||
|
||||
// Common cases.
|
||||
dotCount := strings.Count(pth, ".")
|
||||
if dotCount <= 1 {
|
||||
if dotCount == 0 {
|
||||
// Asume HTML.
|
||||
of, mt = s.resolveOutputFormatAndOrMediaType("html", "")
|
||||
} else {
|
||||
pth = strings.TrimPrefix(pth, "/")
|
||||
ext := path.Ext(pth)
|
||||
pth = strings.TrimSuffix(pth, ext)
|
||||
ext = ext[1:]
|
||||
of, mt = s.resolveOutputFormatAndOrMediaType("", ext)
|
||||
}
|
||||
} else {
|
||||
path := s.opts.PathParser.Parse(files.ComponentFolderLayouts, pth)
|
||||
pth = path.PathNoIdentifier()
|
||||
of, mt = s.resolveOutputFormatAndOrMediaType(path.OutputFormat(), path.Ext())
|
||||
}
|
||||
|
||||
return PathTemplateDescriptor{
|
||||
Path: pth,
|
||||
Desc: TemplateDescriptor{
|
||||
OutputFormat: of.Name,
|
||||
MediaType: mt.Type,
|
||||
IsPlainText: of.IsPlainText,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// resolveOutputFormatAndOrMediaType resolves the output format and/or media type
|
||||
// based on the given output format suffix and media type suffix.
|
||||
// Either of the suffixes can be empty, and the function will try to find a match
|
||||
|
Reference in New Issue
Block a user