mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 06:00:25 +03:00
parent
5dd06b4136
commit
4174a7866b
7 changed files with 113 additions and 19 deletions
|
@ -29,6 +29,9 @@ var defaultPathParser PathParser
|
|||
type PathParser struct {
|
||||
// Maps the language code to its index in the languages/sites slice.
|
||||
LanguageIndex map[string]int
|
||||
|
||||
// Reports whether the given language is disabled.
|
||||
IsLangDisabled func(string) bool
|
||||
}
|
||||
|
||||
// Parse parses component c with path s into Path using the default path parser.
|
||||
|
@ -134,7 +137,16 @@ func (pp *PathParser) doParse(component, s string) (*Path, error) {
|
|||
s := p.s[id.Low:id.High]
|
||||
|
||||
if hasLang {
|
||||
if _, found := pp.LanguageIndex[s]; found {
|
||||
var disabled bool
|
||||
_, langFound := pp.LanguageIndex[s]
|
||||
if !langFound {
|
||||
disabled = pp.IsLangDisabled != nil && pp.IsLangDisabled(s)
|
||||
if disabled {
|
||||
p.disabled = true
|
||||
langFound = true
|
||||
}
|
||||
}
|
||||
if langFound {
|
||||
p.posIdentifierLanguage = 1
|
||||
p.identifiers = append(p.identifiers, id)
|
||||
}
|
||||
|
@ -220,6 +232,7 @@ type Path struct {
|
|||
identifiers []types.LowHigh
|
||||
|
||||
posIdentifierLanguage int
|
||||
disabled bool
|
||||
|
||||
trimLeadingSlash bool
|
||||
|
||||
|
@ -435,6 +448,10 @@ func (p *Path) Identifier(i int) string {
|
|||
return p.identifierAsString(i)
|
||||
}
|
||||
|
||||
func (p *Path) Disabled() bool {
|
||||
return p.disabled
|
||||
}
|
||||
|
||||
func (p *Path) Identifiers() []string {
|
||||
ids := make([]string, len(p.identifiers))
|
||||
for i, id := range p.identifiers {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue