2020-02-02 02:00:47 +01:00
|
|
|
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)
|
|
|
|
}
|
2020-02-02 02:00:47 +01:00
|
|
|
|
|
|
|
// SlugToTitle converts a slug back to a title
|
|
|
|
func SlugToTitle(s string) string {
|
|
|
|
if s == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return Title(strings.Join(Words(s), " "))
|
|
|
|
}
|