photoprism/pkg/txt/slug.go

28 lines
422 B
Go
Raw Normal View History

package txt
2021-09-23 23:46:17 +02:00
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), " "))
}