Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e16b71

Browse files
author
Openset
committed
Update: tag
1 parent d9e4633 commit 7e16b71

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

‎internal/leetcode/tag.go‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import (
1111
"github.com/openset/leetcode/internal/client"
1212
)
1313

14-
func InitTags() {
14+
var initTags []tagType
15+
16+
func init() {
1517
html := remember(problemsetAllFile, 7, func() []byte {
1618
return client.Get(problemsetAllUrl)
1719
})
18-
var tags []tagType
1920
reg := regexp.MustCompile(`href="/tag/(\S+?)/"`)
2021
for _, matches := range reg.FindAllStringSubmatch(string(html), -1) {
2122
if len(matches) >= 2 {
22-
tags = append(tags, tagType{Slug: matches[1]})
23+
initTags = append(initTags, tagType{Slug: matches[1]})
2324
}
2425
}
25-
saveTags(tags, true)
2626
}
2727

2828
func GetTags() (tags []tagType) {
@@ -32,17 +32,14 @@ func GetTags() (tags []tagType) {
3232
return
3333
}
3434

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...)
4137
filePutContents("tag/tags.json", jsonEncode(tagsUnique(tags)))
4238
}
4339

4440
func tagsUnique(tags []tagType) []tagType {
4541
rs, top := make([]tagType, 0, len(tags)), 1
42+
tags = append(initTags, tags...)
4643
var flag = make(map[string]int)
4744
for _, tag := range tags {
4845
i := flag[tag.Slug]
@@ -114,7 +111,7 @@ func (question ttQuestionType) TagsStr() string {
114111
for _, tag := range question.TopicTags {
115112
buf.WriteString(fmt.Sprintf(format, tag.ShowName(), tag.Slug))
116113
}
117-
saveTags(question.TopicTags, false)
114+
saveTags(question.TopicTags)
118115
return string(buf.Bytes())
119116
}
120117

‎internal/tag/tag.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func runTag(cmd *base.Command, args []string) {
2828
buf.WriteString("| :-: | - | :-: | - | :-: | - | :-: |\n")
2929
format := "| %d | [%s](https://github.com/openset/leetcode/tree/master/tag/%s/README.md) | [%s](https://github.com/openset/leetcode/tree/master/tag/%s/README.md) | "
3030
n := buf.Len()
31-
leetcode.InitTags()
3231
for times := 0; times < 2; times++ {
3332
buf.Truncate(n)
3433
tags := leetcode.GetTags()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /