@@ -25,20 +25,16 @@ import (
25
25
"github.com/gohugoio/hugo/identity"
26
26
)
27
27
28
- var defaultPathParser PathParser
29
-
30
28
// PathParser parses a path into a Path.
31
29
type PathParser struct {
32
30
// Maps the language code to its index in the languages/sites slice.
33
31
LanguageIndex map [string ]int
34
32
35
33
// Reports whether the given language is disabled.
36
34
IsLangDisabled func (string ) bool
37
- }
38
35
39
- // Parse parses component c with path s into Path using the default path parser.
40
- func Parse (c , s string ) * Path {
41
- return defaultPathParser .Parse (c , s )
36
+ // Reports whether the given ext is a content file.
37
+ IsContentExt func (string ) bool
42
38
}
43
39
44
40
// NormalizePathString returns a normalized path string using the very basic Hugo rules.
@@ -108,7 +104,6 @@ func (pp *PathParser) parse(component, s string) (*Path, error) {
108
104
var err error
109
105
// Preserve the original case for titles etc.
110
106
p .unnormalized , err = pp .doParse (component , s , pp .newPath (component ))
111
-
112
107
if err != nil {
113
108
return nil , err
114
109
}
@@ -195,23 +190,26 @@ func (pp *PathParser) doParse(component, s string, p *Path) (*Path, error) {
195
190
}
196
191
}
197
192
198
- isContentComponent := p .component == files .ComponentFolderContent || p .component == files .ComponentFolderArchetypes
199
- isContent := isContentComponent && files .IsContentExt (p .Ext ())
200
-
201
- if isContent {
193
+ if len (p .identifiers ) > 0 {
194
+ isContentComponent := p .component == files .ComponentFolderContent || p .component == files .ComponentFolderArchetypes
195
+ isContent := isContentComponent && pp .IsContentExt (p .Ext ())
202
196
id := p .identifiers [len (p .identifiers )- 1 ]
203
197
b := p .s [p .posContainerHigh : id .Low - 1 ]
204
- switch b {
205
- case "index" :
206
- p .bundleType = PathTypeLeaf
207
- case "_index" :
208
- p .bundleType = PathTypeBranch
209
- default :
210
- p .bundleType = PathTypeContentSingle
211
- }
198
+ if isContent {
199
+ switch b {
200
+ case "index" :
201
+ p .bundleType = PathTypeLeaf
202
+ case "_index" :
203
+ p .bundleType = PathTypeBranch
204
+ default :
205
+ p .bundleType = PathTypeContentSingle
206
+ }
212
207
213
- if slashCount == 2 && p .IsLeafBundle () {
214
- p .posSectionHigh = 0
208
+ if slashCount == 2 && p .IsLeafBundle () {
209
+ p .posSectionHigh = 0
210
+ }
211
+ } else if b == files .NameContentData && files .IsContentDataExt (p .Ext ()) {
212
+ p .bundleType = PathTypeContentData
215
213
}
216
214
}
217
215
@@ -246,6 +244,9 @@ const (
246
244
247
245
// Branch bundles, e.g. /blog/_index.md
248
246
PathTypeBranch
247
+
248
+ // Content data file, _content.gotmpl.
249
+ PathTypeContentData
249
250
)
250
251
251
252
type Path struct {
@@ -521,10 +522,6 @@ func (p *Path) Identifiers() []string {
521
522
return ids
522
523
}
523
524
524
- func (p * Path ) IsHTML () bool {
525
- return files .IsHTML (p .Ext ())
526
- }
527
-
528
525
func (p * Path ) BundleType () PathType {
529
526
return p .bundleType
530
527
}
@@ -541,6 +538,10 @@ func (p *Path) IsLeafBundle() bool {
541
538
return p .bundleType == PathTypeLeaf
542
539
}
543
540
541
+ func (p * Path ) IsContentData () bool {
542
+ return p .bundleType == PathTypeContentData
543
+ }
544
+
544
545
func (p Path ) ForBundleType (t PathType ) * Path {
545
546
p .bundleType = t
546
547
return & p
0 commit comments