forked from bingsoo420/4ch-general
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.go
More file actions
30 lines (23 loc) · 643 Bytes
/
parser.go
File metadata and controls
30 lines (23 loc) · 643 Bytes
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
package main
import (
"fmt"
"regexp"
"strings"
)
func ParseSubject(subject string) (bool, string) {
re := regexp.MustCompile(`\/\w+\/`)
found := re.Find([]byte(subject))
return len(found) > 0, strings.Trim(string(found), "/")
}
func BuildGenerals(board string, catalog Catalog) map[string]string {
generals := make(map[string]string)
for _, page := range catalog {
for _, thread := range page.Threads {
if isGeneral, name := ParseSubject(thread.Sub); isGeneral {
name := strings.ToLower(name)
generals[name] = fmt.Sprintf("https://boards.4channel.org/%s/thread/%d", board, thread.No)
}
}
}
return generals
}