-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtagify.go
64 lines (53 loc) · 1.24 KB
/
tagify.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
package tagify
import (
"context"
"fmt"
"github.com/zoomio/tagify/config"
"github.com/zoomio/tagify/model"
"github.com/zoomio/tagify/processor"
"github.com/zoomio/tagify/processor/html"
"github.com/zoomio/tagify/processor/md"
"github.com/zoomio/tagify/processor/text"
)
// Run produces slice of tags ordered by frequency.
func Run(ctx context.Context, options ...Option) (*model.Result, error) {
cfg := config.New(options...)
var in in
var err error
if cfg.Content != "" {
in = newInFromString(cfg.Content, cfg.ContentType)
} else {
in, err = newIn(ctx, cfg)
if cfg.ContentType > Unknown {
in.ContentType = cfg.ContentType
}
}
if err != nil {
return nil, err
}
res := processInput(&in, cfg)
if len(res.RawTags) > 0 {
if cfg.Verbose {
fmt.Println("tagifying...")
}
res.Tags = processor.Run(cfg, res.Flatten())
if cfg.Verbose {
fmt.Printf("\n%v\n", res.Tags)
}
}
return res, nil
}
func processInput(in *in, c *Config) *model.Result {
switch in.ContentType {
case HTML:
res := html.ProcessHTML(c, in)
if c.Screenshot && len(in.reader.ImgBytes) > 0 {
res.Meta.Screenshot = in.reader.ImgBytes
}
return res
case Markdown:
return md.ProcessMD(c, in)
default:
return text.ProcessText(c, in)
}
}