Change: first process string with custom subs
Previously symbols in defaultSub could not be overwritten by user substitutions
This commit is contained in:
parent
53e7a15aa5
commit
fc91ac8a35
13
slug.go
13
slug.go
@ -38,7 +38,12 @@ func Make(s string) (slug string) {
|
|||||||
func MakeLang(s string, lang string) (slug string) {
|
func MakeLang(s string, lang string) (slug string) {
|
||||||
slug = strings.TrimSpace(s)
|
slug = strings.TrimSpace(s)
|
||||||
|
|
||||||
// Select substitution language
|
// Custom substitutions
|
||||||
|
// Always substitute runes first
|
||||||
|
slug = SubstituteRune(slug, CustomRuneSub)
|
||||||
|
slug = Substitute(slug, CustomSub)
|
||||||
|
|
||||||
|
// Process string with selected substitution language
|
||||||
switch lang {
|
switch lang {
|
||||||
case "de":
|
case "de":
|
||||||
slug = SubstituteRune(slug, deSub)
|
slug = SubstituteRune(slug, deSub)
|
||||||
@ -52,14 +57,12 @@ func MakeLang(s string, lang string) (slug string) {
|
|||||||
|
|
||||||
slug = SubstituteRune(slug, defaultSub)
|
slug = SubstituteRune(slug, defaultSub)
|
||||||
|
|
||||||
// Custom substitutions
|
// Process all non ASCII symbols
|
||||||
slug = SubstituteRune(slug, CustomRuneSub)
|
|
||||||
slug = Substitute(slug, CustomSub)
|
|
||||||
|
|
||||||
slug = unidecode.Unidecode(slug)
|
slug = unidecode.Unidecode(slug)
|
||||||
|
|
||||||
slug = strings.ToLower(slug)
|
slug = strings.ToLower(slug)
|
||||||
|
|
||||||
|
// Process all remaining symbols
|
||||||
slug = regexp.MustCompile("[^a-z0-9-_]").ReplaceAllString(slug, "-")
|
slug = regexp.MustCompile("[^a-z0-9-_]").ReplaceAllString(slug, "-")
|
||||||
slug = regexp.MustCompile("-+").ReplaceAllString(slug, "-")
|
slug = regexp.MustCompile("-+").ReplaceAllString(slug, "-")
|
||||||
slug = strings.Trim(slug, "-")
|
slug = strings.Trim(slug, "-")
|
||||||
|
Loading…
Reference in New Issue
Block a user