2020-07-13 14:20:43 +02:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
const (
|
2020-07-16 13:02:48 +02:00
|
|
|
KeywordFlash = "flash"
|
|
|
|
KeywordHdr = "hdr"
|
|
|
|
KeywordBurst = "burst"
|
|
|
|
KeywordPanorama = "panorama"
|
|
|
|
KeywordEquirectangular = "equirectangular"
|
2020-07-13 14:20:43 +02:00
|
|
|
)
|
|
|
|
|
2020-07-16 13:02:48 +02:00
|
|
|
var AutoKeywords = []string{KeywordHdr, KeywordBurst, KeywordPanorama, KeywordEquirectangular}
|
2020-07-13 14:20:43 +02:00
|
|
|
|
|
|
|
// AddKeyword appends a keyword if not exists.
|
|
|
|
func (data *Data) AddKeyword(w string) {
|
|
|
|
w = strings.ToLower(SanitizeString(w))
|
|
|
|
|
|
|
|
if len(w) < 3 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(data.Keywords, w) {
|
|
|
|
if data.Keywords == "" {
|
|
|
|
data.Keywords = w
|
|
|
|
} else {
|
|
|
|
data.Keywords += ", " + w
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AutoAddKeywords automatically adds relevant keywords from a string (e.g. description).
|
|
|
|
func (data *Data) AutoAddKeywords(s string) {
|
|
|
|
s = strings.ToLower(SanitizeString(s))
|
|
|
|
|
|
|
|
if len(s) < 3 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, w := range AutoKeywords {
|
|
|
|
if strings.Contains(s, w) {
|
|
|
|
data.AddKeyword(w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|