@@ -11,18 +11,18 @@ import (
11
11
"github.com/openset/leetcode/internal/client"
12
12
)
13
13
14
- func InitTags () {
14
+ var initTags []tagType
15
+
16
+ func init () {
15
17
html := remember (problemsetAllFile , 7 , func () []byte {
16
18
return client .Get (problemsetAllUrl )
17
19
})
18
- var tags []tagType
19
20
reg := regexp .MustCompile (`href="/tag/(\S+?)/"` )
20
21
for _ , matches := range reg .FindAllStringSubmatch (string (html ), - 1 ) {
21
22
if len (matches ) >= 2 {
22
- tags = append (tags , tagType {Slug : matches [1 ]})
23
+ initTags = append (initTags , tagType {Slug : matches [1 ]})
23
24
}
24
25
}
25
- saveTags (tags , true )
26
26
}
27
27
28
28
func GetTags () (tags []tagType ) {
@@ -32,17 +32,14 @@ func GetTags() (tags []tagType) {
32
32
return
33
33
}
34
34
35
- func saveTags (tags []tagType , isBase bool ) {
36
- if isBase {
37
- tags = append (tags , GetTags ()... )
38
- } else {
39
- tags = append (GetTags (), tags ... )
40
- }
35
+ func saveTags (tags []tagType ) {
36
+ tags = append (GetTags (), tags ... )
41
37
filePutContents ("tag/tags.json" , jsonEncode (tagsUnique (tags )))
42
38
}
43
39
44
40
func tagsUnique (tags []tagType ) []tagType {
45
41
rs , top := make ([]tagType , 0 , len (tags )), 1
42
+ tags = append (initTags , tags ... )
46
43
var flag = make (map [string ]int )
47
44
for _ , tag := range tags {
48
45
i := flag [tag .Slug ]
@@ -114,7 +111,7 @@ func (question ttQuestionType) TagsStr() string {
114
111
for _ , tag := range question .TopicTags {
115
112
buf .WriteString (fmt .Sprintf (format , tag .ShowName (), tag .Slug ))
116
113
}
117
- saveTags (question .TopicTags , false )
114
+ saveTags (question .TopicTags )
118
115
return string (buf .Bytes ())
119
116
}
120
117
0 commit comments