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 d9e4633

Browse files
author
Openset
committed
Add: InitTags
1 parent a5c5488 commit d9e4633

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

‎internal/leetcode/tag.go‎

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

14+
func InitTags() {
15+
html := remember(problemsetAllFile, 7, func() []byte {
16+
return client.Get(problemsetAllUrl)
17+
})
18+
var tags []tagType
19+
reg := regexp.MustCompile(`href="/tag/(\S+?)/"`)
20+
for _, matches := range reg.FindAllStringSubmatch(string(html), -1) {
21+
if len(matches) >= 2 {
22+
tags = append(tags, tagType{Slug: matches[1]})
23+
}
24+
}
25+
saveTags(tags, true)
26+
}
27+
1428
func GetTags() (tags []tagType) {
1529
cts := fileGetContents("tag/tags.json")
1630
jsonDecode(cts, &tags)
@@ -141,17 +155,3 @@ func (tag tagType) ShowName() string {
141155
}
142156
return tag.Name
143157
}
144-
145-
func init() {
146-
html := remember(problemsetAllFile, 7, func() []byte {
147-
return client.Get(problemsetAllUrl)
148-
})
149-
var tags []tagType
150-
reg := regexp.MustCompile(`href="/tag/(\S+?)/"`)
151-
for _, matches := range reg.FindAllStringSubmatch(string(html), -1) {
152-
if len(matches) >= 2 {
153-
tags = append(tags, tagType{Slug: matches[1]})
154-
}
155-
}
156-
saveTags(tags, true)
157-
}

‎internal/tag/tag.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ 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()
3132
for times := 0; times < 2; times++ {
3233
buf.Truncate(n)
3334
tags := leetcode.GetTags()

0 commit comments

Comments
(0)

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