photoprism/pkg/txt/slug.go
2021-09-23 23:46:17 +02:00

27 lines
422 B
Go

package txt
import (
"strings"
"github.com/gosimple/slug"
)
// Slug converts a string to a valid slug with a max length of 80 runes.
func Slug(s string) string {
s = strings.TrimSpace(s)
if s == "" {
return ""
}
return Clip(slug.Make(s), ClipSlug)
}
// SlugToTitle converts a slug back to a title
func SlugToTitle(s string) string {
if s == "" {
return ""
}
return Title(strings.Join(Words(s), " "))
}