@@ -124,24 +124,25 @@ func (pp *PathParser) parseIdentifier(component, s string, p *Path, i, lastDot i
124
124
if p .posContainerHigh != - 1 {
125
125
return
126
126
}
127
- mayHaveLang := pp .LanguageIndex != nil
127
+ mayHaveLang := p . posIdentifierLanguage == - 1 && pp .LanguageIndex != nil
128
128
mayHaveLang = mayHaveLang && (component == files .ComponentFolderContent || component == files .ComponentFolderLayouts )
129
129
mayHaveOutputFormat := component == files .ComponentFolderLayouts
130
- mayHaveKind := mayHaveOutputFormat
130
+ mayHaveKind := p .posIdentifierKind == - 1 && mayHaveOutputFormat
131
+ mayHaveLayout := component == files .ComponentFolderLayouts
131
132
132
133
var found bool
133
134
var high int
134
- if len (p .identifiers ) > 0 {
135
+ if len (p .identifiersKnown ) > 0 {
135
136
high = lastDot
136
137
} else {
137
138
high = len (p .s )
138
139
}
139
140
id := types.LowHigh [string ]{Low : i + 1 , High : high }
140
141
sid := p .s [id .Low :id .High ]
141
142
142
- if len (p .identifiers ) == 0 {
143
+ if len (p .identifiersKnown ) == 0 {
143
144
// The first is always the extension.
144
- p .identifiers = append (p .identifiers , id )
145
+ p .identifiersKnown = append (p .identifiersKnown , id )
145
146
found = true
146
147
147
148
// May also be the output format.
@@ -164,8 +165,8 @@ func (pp *PathParser) parseIdentifier(component, s string, p *Path, i, lastDot i
164
165
}
165
166
found = langFound
166
167
if langFound {
167
- p .identifiers = append (p .identifiers , id )
168
- p .posIdentifierLanguage = len (p .identifiers ) - 1
168
+ p .identifiersKnown = append (p .identifiersKnown , id )
169
+ p .posIdentifierLanguage = len (p .identifiersKnown ) - 1
169
170
170
171
}
171
172
}
@@ -177,28 +178,33 @@ func (pp *PathParser) parseIdentifier(component, s string, p *Path, i, lastDot i
177
178
// false positives on the form css.html.
178
179
if pp .IsOutputFormat (sid , p .Ext ()) {
179
180
found = true
180
- p .identifiers = append (p .identifiers , id )
181
- p .posIdentifierOutputFormat = len (p .identifiers ) - 1
181
+ p .identifiersKnown = append (p .identifiersKnown , id )
182
+ p .posIdentifierOutputFormat = len (p .identifiersKnown ) - 1
182
183
}
183
184
}
184
185
185
186
if ! found && mayHaveKind {
186
187
if kinds .GetKindMain (sid ) != "" {
187
188
found = true
188
- p .identifiers = append (p .identifiers , id )
189
- p .posIdentifierKind = len (p .identifiers ) - 1
189
+ p .identifiersKnown = append (p .identifiersKnown , id )
190
+ p .posIdentifierKind = len (p .identifiersKnown ) - 1
190
191
}
191
192
}
192
193
193
194
if ! found && sid == identifierBaseof {
194
195
found = true
195
- p .identifiers = append (p .identifiers , id )
196
- p .posIdentifierBaseof = len (p .identifiers ) - 1
196
+ p .identifiersKnown = append (p .identifiersKnown , id )
197
+ p .posIdentifierBaseof = len (p .identifiersKnown ) - 1
198
+ }
199
+
200
+ if ! found && mayHaveLayout {
201
+ p .identifiersKnown = append (p .identifiersKnown , id )
202
+ p .posIdentifierLayout = len (p .identifiersKnown ) - 1
203
+ found = true
197
204
}
198
205
199
206
if ! found {
200
- p .identifiers = append (p .identifiers , id )
201
- p .identifiersUnknown = append (p .identifiersUnknown , len (p .identifiers )- 1 )
207
+ p .identifiersUnknown = append (p .identifiersUnknown , id )
202
208
}
203
209
204
210
}
@@ -252,13 +258,13 @@ func (pp *PathParser) doParse(component, s string, p *Path) (*Path, error) {
252
258
}
253
259
}
254
260
255
- if len (p .identifiers ) > 0 {
261
+ if len (p .identifiersKnown ) > 0 {
256
262
isContentComponent := p .component == files .ComponentFolderContent || p .component == files .ComponentFolderArchetypes
257
263
isContent := isContentComponent && pp .IsContentExt (p .Ext ())
258
- id := p .identifiers [len (p .identifiers )- 1 ]
264
+ id := p .identifiersKnown [len (p .identifiersKnown )- 1 ]
259
265
260
- if id .High > p .posContainerHigh {
261
- b := p .s [p .posContainerHigh : id .High ]
266
+ if id .Low > p .posContainerHigh {
267
+ b := p .s [p .posContainerHigh : id .Low - 1 ]
262
268
if isContent {
263
269
switch b {
264
270
case "index" :
@@ -294,6 +300,16 @@ func (pp *PathParser) doParse(component, s string, p *Path) (*Path, error) {
294
300
}
295
301
}
296
302
303
+ if p .pathType == TypeShortcode && p .posIdentifierLayout != - 1 {
304
+ // myshortcode or myshortcode.html, no layout.
305
+ if len (p .identifiersKnown ) <= 2 {
306
+ p .posIdentifierLayout = - 1
307
+ } else {
308
+ // First is always the name.
309
+ p .posIdentifierLayout --
310
+ }
311
+ }
312
+
297
313
return p , nil
298
314
}
299
315
@@ -350,13 +366,14 @@ type Path struct {
350
366
component string
351
367
pathType Type
352
368
353
- identifiers []types.LowHigh [string ]
369
+ identifiersKnown []types.LowHigh [string ]
370
+ identifiersUnknown []types.LowHigh [string ]
354
371
355
372
posIdentifierLanguage int
356
373
posIdentifierOutputFormat int
357
374
posIdentifierKind int
375
+ posIdentifierLayout int
358
376
posIdentifierBaseof int
359
- identifiersUnknown []int
360
377
disabled bool
361
378
362
379
trimLeadingSlash bool
@@ -388,10 +405,11 @@ func (p *Path) reset() {
388
405
p .posSectionHigh = - 1
389
406
p .component = ""
390
407
p .pathType = 0
391
- p .identifiers = p .identifiers [:0 ]
408
+ p .identifiersKnown = p .identifiersKnown [:0 ]
392
409
p .posIdentifierLanguage = - 1
393
410
p .posIdentifierOutputFormat = - 1
394
411
p .posIdentifierKind = - 1
412
+ p .posIdentifierLayout = - 1
395
413
p .posIdentifierBaseof = - 1
396
414
p .disabled = false
397
415
p .trimLeadingSlash = false
@@ -479,7 +497,7 @@ func (p *Path) Name() string {
479
497
// Name returns the last element of path without any extension.
480
498
func (p * Path ) NameNoExt () string {
481
499
if i := p .identifierIndex (0 ); i != - 1 {
482
- return p .s [p .posContainerHigh : p .identifiers [i ].Low - 1 ]
500
+ return p .s [p .posContainerHigh : p .identifiersKnown [i ].Low - 1 ]
483
501
}
484
502
return p .s [p .posContainerHigh :]
485
503
}
@@ -491,7 +509,7 @@ func (p *Path) NameNoLang() string {
491
509
return p .Name ()
492
510
}
493
511
494
- return p .s [p .posContainerHigh :p .identifiers [i ].Low - 1 ] + p .s [p .identifiers [i ].High :]
512
+ return p .s [p .posContainerHigh :p .identifiersKnown [i ].Low - 1 ] + p .s [p .identifiersKnown [i ].High :]
495
513
}
496
514
497
515
// BaseNameNoIdentifier returns the logical base name for a resource without any identifier (e.g. no extension).
@@ -510,15 +528,15 @@ func (p *Path) NameNoIdentifier() string {
510
528
}
511
529
512
530
func (p * Path ) nameLowHigh () types.LowHigh [string ] {
513
- if len (p .identifiers ) > 0 {
514
- lastID := p .identifiers [len (p .identifiers )- 1 ]
531
+ if len (p .identifiersKnown ) > 0 {
532
+ lastID := p .identifiersKnown [len (p .identifiersKnown )- 1 ]
515
533
if p .posContainerHigh == lastID .Low {
516
534
// The last identifier is the name.
517
535
return lastID
518
536
}
519
537
return types.LowHigh [string ]{
520
538
Low : p .posContainerHigh ,
521
- High : p .identifiers [len (p .identifiers )- 1 ].Low - 1 ,
539
+ High : p .identifiersKnown [len (p .identifiersKnown )- 1 ].Low - 1 ,
522
540
}
523
541
}
524
542
return types.LowHigh [string ]{
@@ -566,7 +584,7 @@ func (p *Path) PathNoIdentifier() string {
566
584
567
585
// PathBeforeLangAndOutputFormatAndExt returns the path up to the first identifier that is not a language or output format.
568
586
func (p * Path ) PathBeforeLangAndOutputFormatAndExt () string {
569
- if len (p .identifiers ) == 0 {
587
+ if len (p .identifiersKnown ) == 0 {
570
588
return p .norm (p .s )
571
589
}
572
590
i := p .identifierIndex (0 )
@@ -582,7 +600,7 @@ func (p *Path) PathBeforeLangAndOutputFormatAndExt() string {
582
600
return p .norm (p .s )
583
601
}
584
602
585
- id := p .identifiers [i ]
603
+ id := p .identifiersKnown [i ]
586
604
return p .norm (p .s [:id .Low - 1 ])
587
605
}
588
606
@@ -633,11 +651,11 @@ func (p *Path) BaseNoLeadingSlash() string {
633
651
}
634
652
635
653
func (p * Path ) base (preserveExt , isBundle bool ) string {
636
- if len (p .identifiers ) == 0 {
654
+ if len (p .identifiersKnown ) == 0 {
637
655
return p .norm (p .s )
638
656
}
639
657
640
- if preserveExt && len (p .identifiers ) == 1 {
658
+ if preserveExt && len (p .identifiersKnown ) == 1 {
641
659
// Preserve extension.
642
660
return p .norm (p .s )
643
661
}
@@ -659,7 +677,7 @@ func (p *Path) base(preserveExt, isBundle bool) string {
659
677
}
660
678
661
679
// For txt files etc. we want to preserve the extension.
662
- id := p .identifiers [0 ]
680
+ id := p .identifiersKnown [0 ]
663
681
664
682
return p .norm (p .s [:high ] + p .s [id .Low - 1 :id .High ])
665
683
}
@@ -676,6 +694,10 @@ func (p *Path) Kind() string {
676
694
return p .identifierAsString (p .posIdentifierKind )
677
695
}
678
696
697
+ func (p * Path ) Layout () string {
698
+ return p .identifierAsString (p .posIdentifierLayout )
699
+ }
700
+
679
701
func (p * Path ) Lang () string {
680
702
return p .identifierAsString (p .posIdentifierLanguage )
681
703
}
@@ -689,8 +711,8 @@ func (p *Path) Disabled() bool {
689
711
}
690
712
691
713
func (p * Path ) Identifiers () []string {
692
- ids := make ([]string , len (p .identifiers ))
693
- for i , id := range p .identifiers {
714
+ ids := make ([]string , len (p .identifiersKnown ))
715
+ for i , id := range p .identifiersKnown {
694
716
ids [i ] = p .s [id .Low :id .High ]
695
717
}
696
718
return ids
@@ -699,7 +721,7 @@ func (p *Path) Identifiers() []string {
699
721
func (p * Path ) IdentifiersUnknown () []string {
700
722
ids := make ([]string , len (p .identifiersUnknown ))
701
723
for i , id := range p .identifiersUnknown {
702
- ids [i ] = p .s [p . identifiers [ id ] .Low :p . identifiers [ id ] .High ]
724
+ ids [i ] = p .s [id .Low :id .High ]
703
725
}
704
726
return ids
705
727
}
@@ -735,12 +757,12 @@ func (p *Path) identifierAsString(i int) string {
735
757
return ""
736
758
}
737
759
738
- id := p .identifiers [i ]
760
+ id := p .identifiersKnown [i ]
739
761
return p .s [id .Low :id .High ]
740
762
}
741
763
742
764
func (p * Path ) identifierIndex (i int ) int {
743
- if i < 0 || i >= len (p .identifiers ) {
765
+ if i < 0 || i >= len (p .identifiersKnown ) {
744
766
return - 1
745
767
}
746
768
return i
0 commit comments