diff options
Diffstat (limited to 'common/paths/pathparser.go')
-rw-r--r-- | common/paths/pathparser.go | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/common/paths/pathparser.go b/common/paths/pathparser.go index b0a2f9fc4..8b9259bf7 100644 --- a/common/paths/pathparser.go +++ b/common/paths/pathparser.go @@ -120,15 +120,20 @@ func (pp *PathParser) parse(component, s string) (*Path, error) { return p, nil } -func (pp *PathParser) parseIdentifier(component, s string, p *Path, i, lastDot int) { +func (pp *PathParser) parseIdentifier(component, s string, p *Path, i, lastDot, numDots int, isLast bool) { if p.posContainerHigh != -1 { return } - mayHaveLang := p.posIdentifierLanguage == -1 && pp.LanguageIndex != nil + mayHaveLang := numDots > 1 && p.posIdentifierLanguage == -1 && pp.LanguageIndex != nil mayHaveLang = mayHaveLang && (component == files.ComponentFolderContent || component == files.ComponentFolderLayouts) mayHaveOutputFormat := component == files.ComponentFolderLayouts mayHaveKind := p.posIdentifierKind == -1 && mayHaveOutputFormat - mayHaveLayout := component == files.ComponentFolderLayouts + var mayHaveLayout bool + if p.pathType == TypeShortcode { + mayHaveLayout = !isLast && component == files.ComponentFolderLayouts + } else { + mayHaveLayout = component == files.ComponentFolderLayouts + } var found bool var high int @@ -167,7 +172,6 @@ func (pp *PathParser) parseIdentifier(component, s string, p *Path, i, lastDot i if langFound { p.identifiersKnown = append(p.identifiersKnown, id) p.posIdentifierLanguage = len(p.identifiersKnown) - 1 - } } @@ -234,19 +238,24 @@ func (pp *PathParser) doParse(component, s string, p *Path) (*Path, error) { p.s = s slashCount := 0 lastDot := 0 + lastSlashIdx := strings.LastIndex(s, "/") + numDots := strings.Count(s[lastSlashIdx+1:], ".") + if strings.Contains(s, "/_shortcodes/") { + p.pathType = TypeShortcode + } for i := len(s) - 1; i >= 0; i-- { c := s[i] switch c { case '.': - pp.parseIdentifier(component, s, p, i, lastDot) + pp.parseIdentifier(component, s, p, i, lastDot, numDots, false) lastDot = i case '/': slashCount++ if p.posContainerHigh == -1 { if lastDot > 0 { - pp.parseIdentifier(component, s, p, i, lastDot) + pp.parseIdentifier(component, s, p, i, lastDot, numDots, true) } p.posContainerHigh = i + 1 } else if p.posContainerLow == -1 { @@ -282,10 +291,9 @@ func (pp *PathParser) doParse(component, s string, p *Path) (*Path, error) { p.pathType = TypeContentData } } - } - if component == files.ComponentFolderLayouts { + if p.pathType < TypeMarkup && component == files.ComponentFolderLayouts { if p.posIdentifierBaseof != -1 { p.pathType = TypeBaseof } else { @@ -301,12 +309,10 @@ func (pp *PathParser) doParse(component, s string, p *Path) (*Path, error) { } if p.pathType == TypeShortcode && p.posIdentifierLayout != -1 { - // myshortcode or myshortcode.html, no layout. - if len(p.identifiersKnown) <= 2 { + id := p.identifiersKnown[p.posIdentifierLayout] + if id.Low == p.posContainerHigh { + // First identifier is shortcode name. p.posIdentifierLayout = -1 - } else { - // First is always the name. - p.posIdentifierLayout-- } } @@ -634,7 +640,7 @@ func (p *Path) Base() string { // For pages with Type set, we treat that as the section. func (p *Path) BaseReTyped(typ string) (d string) { base := p.Base() - if typ == "" || p.Section() == typ { + if p.Section() == typ { return base } d = "/" + typ |