Skip to content

Commit e81d0f2

Browse files
committed
fix source sort bug
1 parent fbbbc97 commit e81d0f2

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

pkg/collector/model/main_markdown.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const markdownTemplate = `
3333
<br>
3434
</p>
3535
<!--请保留下面这行信息,让更多用户了解到这个小爬虫,衷心感谢您的支持-->
36-
<p align="center">The source code is fetched using the tool <a href="https://github.com/realzhangm/leetcode_collector">leetcode_collector</a>.</p>
36+
<p align="center"> 生成 By <a href="https://github.com/realzhangm/leetcode_collector">leetcode_collector</a>.</p>
3737
3838
<p align="center"> 查看 <a href="./TAGS.md">标签视角</a>.</p>
3939
@@ -133,7 +133,7 @@ type SubmissionDetailSlice []lccli.SubmissionDetail
133133
func (s SubmissionDetailSlice) Len() int { return len(s) }
134134
func (s SubmissionDetailSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
135135
func (s SubmissionDetailSlice) Less(i, j int) bool {
136-
return strings.Compare(s[i].Lang, s[i].Lang) < 0
136+
return strings.Compare(s[i].Lang, s[j].Lang) < 0
137137
}
138138

139139
type ProblemStatusSlice []lccli.ProblemStatus

pkg/collector/model/output_solutions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (s SolutionReadMeFormatter) solutions() string {
8989
for _, sbd := range s.subLangMap {
9090
subDetailSlice = append(subDetailSlice, sbd)
9191
}
92+
sort.Sort(subDetailSlice)
9293

9394
for _, sbd := range subDetailSlice {
9495
lang := sbd.Lang
@@ -216,7 +217,6 @@ func (p *PersonInfoNode) OutputSolutions(outputDir string) error {
216217
slugDir := path.Join(outputDir, slug)
217218
mkdir(slugDir)
218219

219-
// 保存代码
220220
for _, s := range subLangMap {
221221
p.writeOneSourceCode(slugDir, slug, &s)
222222
}

pkg/collector/model/tags_markdown.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// tags
1616
// tag名.md 文件
17-
//TODO 优化
17+
// TODO 优化
1818

1919
// 题目描述 README 中文模板
2020
const TagsMarkDown = `
@@ -119,10 +119,17 @@ func (p *PersonInfoNode) WriteAllTags(outputDir string) {
119119

120120
tagLinksSlice := make([][]TagsLink, 0, len(p.TagsMap))
121121
for _, tagLink := range p.TagsMap {
122+
sort.Slice(tagLink, func(i, j int) bool {
123+
return strings.Compare(tagLink[i].question.QuestionID, tagLink[j].question.QuestionID) < 0
124+
})
122125
tagLinksSlice = append(tagLinksSlice, tagLink)
123126
}
124127
sort.Slice(tagLinksSlice, func(i, j int) bool {
125-
return len(tagLinksSlice[i]) > len(tagLinksSlice[j])
128+
cmp := len(tagLinksSlice[i]) - len(tagLinksSlice[j])
129+
if cmp == 0 {
130+
return strings.Compare(tagLinksSlice[i][0].topicTag.Slug, tagLinksSlice[j][0].topicTag.Slug) < 0
131+
}
132+
return cmp > 0
126133
})
127134

128135
for _, tagLinks := range tagLinksSlice {

0 commit comments

Comments
 (0)