-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
112 lines (95 loc) · 2.06 KB
/
options.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package readability
import (
"regexp"
"golang.org/x/net/html"
)
type Options struct {
maxElemsToParse int
nbTopCandidates int
charThreshold int
classesToPreserve []string
keepClasses bool
serializer func(doc *Node) string
html2text func(htmlSrc string) string
disableJSONLD bool
allowedVideoRegex *regexp.Regexp
minContentLength int
minScore float64
visibilityChecker func(*html.Node) bool
}
type Option func(*Options)
func defaultOpts() *Options {
return &Options{
maxElemsToParse: defaultMaxElemsToParse,
nbTopCandidates: defaultNTopCandidates,
charThreshold: defaultCharThreshold,
classesToPreserve: classesToPreserve,
allowedVideoRegex: videos,
serializer: func(n *Node) string {
return n.GetInnerHTML()
},
minScore: 20,
minContentLength: 140,
visibilityChecker: isNodeVisible,
}
}
func MaxElemsToParse(n int) Option {
return func(o *Options) {
o.maxElemsToParse = n
}
}
func NTopCandidates(n int) Option {
return func(o *Options) {
o.nbTopCandidates = n
}
}
func CharThreshold(n int) Option {
return func(o *Options) {
o.charThreshold = n
}
}
func ClassesToPreserve(classes ...string) Option {
return func(o *Options) {
o.classesToPreserve = append(o.classesToPreserve, classes...)
}
}
func KeepClasses(b bool) Option {
return func(o *Options) {
o.keepClasses = b
}
}
func Serializer(f func(*Node) string) Option {
return func(o *Options) {
o.serializer = f
}
}
func Html2Text(f func(string) string) Option {
return func(o *Options) {
o.html2text = f
}
}
func DisableJSONLD(b bool) Option {
return func(o *Options) {
o.disableJSONLD = b
}
}
func AllowedVideoRegex(rgx *regexp.Regexp) Option {
return func(o *Options) {
o.allowedVideoRegex = rgx
}
}
func MinContentLength(len int) Option {
return func(o *Options) {
o.minContentLength = len
}
}
func MinScore(score float64) Option {
return func(o *Options) {
o.minScore = score
}
}
func VisibilityChecker(f func(*html.Node) bool) Option {
return func(o *Options) {
o.visibilityChecker = f
}
}