@@ -564,14 +564,21 @@ func (s *TemplateStore) LookupPagesLayout(q TemplateQuery) *TemplInfo {
564564
565565func (s * TemplateStore ) LookupPartial (pth string ) * TemplInfo {
566566 ti , _ := s .cacheLookupPartials .GetOrCreate (pth , func () (* TemplInfo , error ) {
567- d := s .templateDescriptorFromPath (pth )
568- desc := d .Desc
569- if desc .LayoutFromTemplate != "" {
570- panic ("shortcode template descriptor must not have a layout" )
567+ pi := s .opts .PathParser .Parse (files .ComponentFolderLayouts , pth ).ForType (paths .TypePartial )
568+ k1 , _ , _ , desc , err := s .toKeyCategoryAndDescriptor (pi )
569+ if err != nil {
570+ return nil , err
571+ }
572+ if desc .OutputFormat == "" && desc .MediaType == "" {
573+ // Assume HTML.
574+ desc .OutputFormat = s .htmlFormat .Name
575+ desc .MediaType = s .htmlFormat .MediaType .Type
576+ desc .IsPlainText = s .htmlFormat .IsPlainText
571577 }
578+
572579 best := s .getBest ()
573580 defer s .putBest (best )
574- s .findBestMatchGet (s .key (path .Join (containerPartials , d . Path )), CategoryPartial , nil , desc , best )
581+ s .findBestMatchGet (s .key (path .Join (containerPartials , k1 )), CategoryPartial , nil , desc , best )
575582 return best .templ , nil
576583 })
577584
@@ -1486,43 +1493,6 @@ type PathTemplateDescriptor struct {
14861493 Desc TemplateDescriptor
14871494}
14881495
1489- // templateDescriptorFromPath returns a template descriptor from the given path.
1490- // This is currently used in partial lookups only.
1491- func (s * TemplateStore ) templateDescriptorFromPath (pth string ) PathTemplateDescriptor {
1492- var (
1493- mt media.Type
1494- of output.Format
1495- )
1496-
1497- // Common cases.
1498- dotCount := strings .Count (pth , "." )
1499- if dotCount <= 1 {
1500- if dotCount == 0 {
1501- // Asume HTML.
1502- of , mt = s .resolveOutputFormatAndOrMediaType ("html" , "" )
1503- } else {
1504- pth = strings .TrimPrefix (pth , "/" )
1505- ext := path .Ext (pth )
1506- pth = strings .TrimSuffix (pth , ext )
1507- ext = ext [1 :]
1508- of , mt = s .resolveOutputFormatAndOrMediaType ("" , ext )
1509- }
1510- } else {
1511- path := s .opts .PathParser .Parse (files .ComponentFolderLayouts , pth )
1512- pth = path .PathNoIdentifier ()
1513- of , mt = s .resolveOutputFormatAndOrMediaType (path .OutputFormat (), path .Ext ())
1514- }
1515-
1516- return PathTemplateDescriptor {
1517- Path : pth ,
1518- Desc : TemplateDescriptor {
1519- OutputFormat : of .Name ,
1520- MediaType : mt .Type ,
1521- IsPlainText : of .IsPlainText ,
1522- },
1523- }
1524- }
1525-
15261496// resolveOutputFormatAndOrMediaType resolves the output format and/or media type
15271497// based on the given output format suffix and media type suffix.
15281498// Either of the suffixes can be empty, and the function will try to find a match
0 commit comments