1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 05:09:42 +02:00

Use unicode compat slug engine

This commit is contained in:
sauls8t 2018-04-25 12:15:17 +01:00
parent 91c8b05d89
commit 123fce6c17
18 changed files with 48504 additions and 678 deletions

View file

@ -12,28 +12,10 @@
package stringutil
import (
"strings"
"unicode"
"github.com/documize/slug"
)
// TODO" replace with https://github.com/mcmatts/slug
// MakeSlug creates a slug, suitable for use in a URL, from a string
func MakeSlug(str string) string {
slg := strings.Map(
func(r rune) rune { // individual mapping of runes into a format suitable for use in a URL
r = unicode.ToLower(r)
if unicode.IsLower(r) || unicode.IsDigit(r) {
return r
}
return '-'
}, str)
slg = strings.NewReplacer("---", "-", "--", "-").Replace(slg)
for strings.HasSuffix(slg, "-") {
slg = strings.TrimSuffix(slg, "-")
}
for strings.HasPrefix(slg, "-") {
slg = strings.TrimPrefix(slg, "-")
}
return slg
return slug.Make(str)
}