-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
language.go
36 lines (32 loc) · 778 Bytes
/
language.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package filters
import (
"strings"
"github.com/abadojack/whatlanggo"
"github.com/slurdge/goeland/internal/goeland"
"jaytaylor.com/html2text"
)
func StringInSlice(a string, list []string) bool {
for _, b := range list {
if strings.EqualFold(b, a) {
return true
}
}
return false
}
func filterLanguage(source *goeland.Source, params *filterParams) {
languages := params.args
var current int
for _, entry := range source.Entries {
text, err := html2text.FromString(entry.Content, html2text.Options{OmitLinks: true})
if err != nil {
text = entry.Content
}
lang := whatlanggo.DetectLang(text)
if !StringInSlice(lang.Iso6391(), languages) {
continue
}
source.Entries[current] = entry
current++
}
source.Entries = source.Entries[:current]
}