@@ -20,6 +20,7 @@ import (
20
20
"time"
21
21
22
22
"github.com/gohugoio/hugo/common/herrors"
23
+ "github.com/gohugoio/hugo/common/loggers"
23
24
"github.com/gohugoio/hugo/common/maps"
24
25
"github.com/gohugoio/hugo/common/paths"
25
26
"github.com/gohugoio/hugo/helpers"
@@ -156,6 +157,9 @@ type StoreOptions struct {
156
157
// The filesystem to use.
157
158
Fs afero.Fs
158
159
160
+ // The logger to use.
161
+ Log loggers.Logger
162
+
159
163
// The path parser to use.
160
164
PathParser * paths.PathParser
161
165
@@ -986,7 +990,10 @@ func (s *TemplateStore) setTemplateByPath(p string, ti *TemplInfo) {
986
990
}
987
991
988
992
func (s * TemplateStore ) insertShortcode (pi * paths.Path , fi hugofs.FileMetaInfo , replace bool , tree doctree.Tree [map [string ]map [TemplateDescriptor ]* TemplInfo ]) (* TemplInfo , error ) {
989
- k1 , k2 , _ , d := s .toKeyCategoryAndDescriptor (pi )
993
+ k1 , k2 , _ , d , err := s .toKeyCategoryAndDescriptor (pi )
994
+ if err != nil {
995
+ return nil , err
996
+ }
990
997
m := tree .Get (k1 )
991
998
if m == nil {
992
999
m = make (map [string ]map [TemplateDescriptor ]* TemplInfo )
@@ -1027,7 +1034,18 @@ func (s *TemplateStore) insertShortcode(pi *paths.Path, fi hugofs.FileMetaInfo,
1027
1034
}
1028
1035
1029
1036
func (s * TemplateStore ) insertTemplate (pi * paths.Path , fi hugofs.FileMetaInfo , replace bool , tree doctree.Tree [map [nodeKey ]* TemplInfo ]) (* TemplInfo , error ) {
1030
- key , _ , category , d := s .toKeyCategoryAndDescriptor (pi )
1037
+ key , _ , category , d , err := s .toKeyCategoryAndDescriptor (pi )
1038
+ // See #13577. Warn for now.
1039
+ if err != nil {
1040
+ var loc string
1041
+ if fi != nil {
1042
+ loc = fmt .Sprintf ("file %q" , fi .Meta ().Filename )
1043
+ } else {
1044
+ loc = fmt .Sprintf ("path %q" , pi .Path ())
1045
+ }
1046
+ s .opts .Log .Warnf ("skipping template %s: %s" , loc , err )
1047
+ return nil , nil
1048
+ }
1031
1049
1032
1050
return s .insertTemplate2 (pi , fi , key , category , d , replace , false , tree )
1033
1051
}
@@ -1481,7 +1499,7 @@ func (s *TemplateStore) templates() iter.Seq[*TemplInfo] {
1481
1499
}
1482
1500
}
1483
1501
1484
- func (s * TemplateStore ) toKeyCategoryAndDescriptor (p * paths.Path ) (string , string , Category , TemplateDescriptor ) {
1502
+ func (s * TemplateStore ) toKeyCategoryAndDescriptor (p * paths.Path ) (string , string , Category , TemplateDescriptor , error ) {
1485
1503
k1 := p .Dir ()
1486
1504
k2 := ""
1487
1505
@@ -1575,7 +1593,7 @@ func (s *TemplateStore) toKeyCategoryAndDescriptor(p *paths.Path) (string, strin
1575
1593
k1 = strings .TrimSuffix (k1 , "/_markup" )
1576
1594
parts := strings .Split (d .Layout , "-" )
1577
1595
if len (parts ) < 2 {
1578
- panic ( "markup template must have at least 2 parts " )
1596
+ return "" , "" , 0 , TemplateDescriptor {}, fmt . Errorf ( "unrecognized render hook template " )
1579
1597
}
1580
1598
// Either 2 or 3 parts, e.g. render-codeblock-go.
1581
1599
d .Variant1 = parts [1 ]
@@ -1585,7 +1603,7 @@ func (s *TemplateStore) toKeyCategoryAndDescriptor(p *paths.Path) (string, strin
1585
1603
d .Layout = "" // This allows using page layout as part of the key for lookups.
1586
1604
}
1587
1605
1588
- return k1 , k2 , category , d
1606
+ return k1 , k2 , category , d , nil
1589
1607
}
1590
1608
1591
1609
func (s * TemplateStore ) transformTemplates () error {
0 commit comments