init
This commit is contained in:
commit
b15b95781c
108 changed files with 14802 additions and 0 deletions
27
internal/slug/slug.go
Normal file
27
internal/slug/slug.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package slug
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func Make(raw string) string {
|
||||
raw = strings.TrimSpace(strings.ToLower(raw))
|
||||
var builder strings.Builder
|
||||
lastDash := false
|
||||
|
||||
for _, r := range raw {
|
||||
switch {
|
||||
case unicode.IsLetter(r), unicode.IsDigit(r):
|
||||
builder.WriteRune(r)
|
||||
lastDash = false
|
||||
default:
|
||||
if !lastDash && builder.Len() > 0 {
|
||||
builder.WriteRune('-')
|
||||
lastDash = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Trim(builder.String(), "-")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue