package pkg import ( "github.com/rainycape/unidecode" "regexp" "strings" ) var ( nonValidChars = regexp.MustCompile("[^a-z0-9-_]") multipleDashes = regexp.MustCompile("-+") ) func slugify(s string) (slug string) { slug = strings.TrimSpace(s) slug = unidecode.Unidecode(slug) slug = strings.ToLower(slug) slug = nonValidChars.ReplaceAllString(slug, "-") slug = multipleDashes.ReplaceAllString(slug, "-") slug = strings.Trim(slug, "-_") return slug }