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) {
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
if langFound {
p.identifiersKnown = append(p.identifiersKnown, id)
p.posIdentifierLanguage = len(p.identifiersKnown) - 1
-
}
}
p.s = s
slashCount := 0
lastDot := 0
+ lastSlashIdx := strings.LastIndex(s, "/")
+ numDots := strings.Count(s[lastSlashIdx+1:], ".")
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)
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)
}
p.posContainerHigh = i + 1
} else if p.posContainerLow == -1 {
c.Assert(p.Type(), qt.Equals, TypePartial)
},
},
+ {
+ "Shortcode lang in root",
+ "/_shortcodes/no.html",
+ func(c *qt.C, p *Path) {
+ c.Assert(p.Type(), qt.Equals, TypeShortcode)
+ c.Assert(p.Lang(), qt.Equals, "")
+ c.Assert(p.NameNoIdentifier(), qt.Equals, "no")
+ },
+ },
}
for _, test := range tests {
c.Run(test.name, func(c *qt.C) {
- if test.name != "Baseof" {
+ if test.name != "Shortcode lang in root" {
// return
}
test.assert(c, testParser.Parse(files.ComponentFolderLayouts, test.path))
b.Assert(err.Error(), qt.Contains, `no compatible template found for shortcode "mymarkdown" in [/_shortcodes/mymarkdown.md]; note that to use plain text template shortcodes in HTML you need to use the shortcode {{% delimiter`)
}
-func TestShortcodeOnlyLanguageInBaseIssue13699(t *testing.T) {
+func TestShortcodeOnlyLanguageInBaseIssue13699And13740(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
baseURL = 'https://example.org/'
+disableLanguages = ['de']
[languages]
[languages.en]
weight = 1
-disableLanguages = ['de']
[languages.de]
weight = 2
-- layouts/_shortcodes/de.html --