// Package slug makes the lower-case, hyphenated names used in addresses // and campaign tags, keeping accented letters as their plain ones // ("Ünïcode" → "unicode") instead of dropping them. package slug import ( "regexp" "strings" "unicode" "golang.org/x/text/unicode/norm" ) // Letters that don't come apart into a plain letter and an accent. var special = strings.NewReplacer("ß", "ss", "æ", "ae", "œ", "oe", "ø", "o", "đ", "d", "ð", "d", "ł", "l", "þ", "th", "ı", "i") var nonSlug = regexp.MustCompile(`[^a-z0-9]+`) // Make turns s into a slug. func Make(s string) string { s = special.Replace(strings.ToLower(s)) var b strings.Builder for _, r := range norm.NFD.String(s) { if !unicode.Is(unicode.Mn, r) { b.WriteRune(r) } } return strings.Trim(nonSlug.ReplaceAllString(b.String(), "-"), "-") }