@@ -11,8 +11,6 @@ import (
11
11
"strconv"
12
12
"strings"
13
13
14
- m "github.com/halfrost/leetcode-go/ctl/models"
15
- "github.com/halfrost/leetcode-go/ctl/util"
16
14
"github.com/spf13/cobra"
17
15
)
18
16
@@ -80,13 +78,13 @@ func newBuildMenu() *cobra.Command {
80
78
81
79
func buildREADME () {
82
80
var (
83
- problems []m. StatStatusPairs
84
- lpa m. LeetCodeProblemAll
85
- info m. UserInfo
81
+ problems []StatStatusPairs
82
+ lpa LeetCodeProblemAll
83
+ info UserInfo
86
84
)
87
85
// 请求所有题目信息
88
86
body := getProblemAllList ()
89
- problemsMap , optimizingIds := map [int ]m. StatStatusPairs {}, []int {}
87
+ problemsMap , optimizingIds := map [int ]StatStatusPairs {}, []int {}
90
88
err := json .Unmarshal (body , & lpa )
91
89
if err != nil {
92
90
fmt .Println (err )
@@ -96,30 +94,30 @@ func buildREADME() {
96
94
97
95
// 拼凑 README 需要渲染的数据
98
96
problems = lpa .StatStatusPairs
99
- info = m . ConvertUserInfoModel (lpa )
97
+ info = ConvertUserInfoModel (lpa )
100
98
for _ , v := range problems {
101
99
problemsMap [int (v .Stat .FrontendQuestionID )] = v
102
100
}
103
- mdrows := m . ConvertMdModelFromSsp (problems )
104
- sort .Sort (m . SortByQuestionID (mdrows ))
105
- solutionIds , _ , try := util . LoadSolutionsDir ()
106
- m . GenerateMdRows (solutionIds , mdrows )
101
+ mdrows := ConvertMdModelFromSsp (problems )
102
+ sort .Sort (SortByQuestionID (mdrows ))
103
+ solutionIds , _ , try := LoadSolutionsDir ()
104
+ GenerateMdRows (solutionIds , mdrows )
107
105
info .EasyTotal , info .MediumTotal , info .HardTotal , info .OptimizingEasy , info .OptimizingMedium , info .OptimizingHard , optimizingIds = statisticalData (problemsMap , solutionIds )
108
- omdrows := m . ConvertMdModelFromIds (problemsMap , optimizingIds )
109
- sort .Sort (m . SortByQuestionID (omdrows ))
106
+ omdrows := ConvertMdModelFromIds (problemsMap , optimizingIds )
107
+ sort .Sort (SortByQuestionID (omdrows ))
110
108
111
109
// 按照模板渲染 README
112
- res , err := renderReadme ("./template/template.markdown" , len (solutionIds ), try , m. Mdrows {Mdrows : mdrows }, m. Mdrows {Mdrows : omdrows }, info )
110
+ res , err := renderReadme ("./template/template.markdown" , len (solutionIds ), try , Mdrows {Mdrows : mdrows }, Mdrows {Mdrows : omdrows }, info )
113
111
if err != nil {
114
112
fmt .Println (err )
115
113
return
116
114
}
117
- util . WriteFile ("../README.md" , res )
115
+ WriteFile ("../README.md" , res )
118
116
fmt .Println ("write file successful" )
119
117
//makeReadmeFile(mds)
120
118
}
121
119
122
- func renderReadme (filePath string , total , try int , mdrows , omdrows m. Mdrows , user m. UserInfo ) ([]byte , error ) {
120
+ func renderReadme (filePath string , total , try int , mdrows , omdrows Mdrows , user UserInfo ) ([]byte , error ) {
123
121
f , err := os .OpenFile (filePath , os .O_RDONLY , 0644 )
124
122
if err != nil {
125
123
return nil , err
@@ -167,8 +165,8 @@ func renderReadme(filePath string, total, try int, mdrows, omdrows m.Mdrows, use
167
165
// false 渲染的链接是外部 HTTPS 链接,用于生成 PDF
168
166
func buildChapterTwo (internal bool ) {
169
167
var (
170
- gr m. GraphQLResp
171
- questions []m. Question
168
+ gr GraphQLResp
169
+ questions []Question
172
170
count int
173
171
)
174
172
for index , tag := range chapterTwoSlug {
@@ -180,39 +178,39 @@ func buildChapterTwo(internal bool) {
180
178
return
181
179
}
182
180
questions = gr .Data .TopicTag .Questions
183
- mdrows := m . ConvertMdModelFromQuestions (questions )
184
- sort .Sort (m . SortByQuestionID (mdrows ))
185
- solutionIds , _ , _ := util . LoadSolutionsDir ()
181
+ mdrows := ConvertMdModelFromQuestions (questions )
182
+ sort .Sort (SortByQuestionID (mdrows ))
183
+ solutionIds , _ , _ := LoadSolutionsDir ()
186
184
tl , err := loadMetaData (fmt .Sprintf ("./meta/%v" , chapterTwoFileName [index ]))
187
185
if err != nil {
188
186
fmt .Printf ("err = %v\n " , err )
189
187
}
190
- tls := m . GenerateTagMdRows (solutionIds , tl , mdrows , internal )
188
+ tls := GenerateTagMdRows (solutionIds , tl , mdrows , internal )
191
189
//fmt.Printf("tls = %v\n", tls)
192
190
// 按照模板渲染 README
193
- res , err := renderChapterTwo (fmt .Sprintf ("./template/%v.md" , chapterTwoFileName [index ]), m. TagLists {TagLists : tls })
191
+ res , err := renderChapterTwo (fmt .Sprintf ("./template/%v.md" , chapterTwoFileName [index ]), TagLists {TagLists : tls })
194
192
if err != nil {
195
193
fmt .Println (err )
196
194
return
197
195
}
198
196
if internal {
199
- util . WriteFile (fmt .Sprintf ("../website/content/ChapterTwo/%v.md" , chapterTwoFileName [index ]), res )
197
+ WriteFile (fmt .Sprintf ("../website/content/ChapterTwo/%v.md" , chapterTwoFileName [index ]), res )
200
198
} else {
201
- util . WriteFile (fmt .Sprintf ("./pdftemp/ChapterTwo/%v.md" , chapterTwoFileName [index ]), res )
199
+ WriteFile (fmt .Sprintf ("./pdftemp/ChapterTwo/%v.md" , chapterTwoFileName [index ]), res )
202
200
}
203
201
204
202
count ++
205
203
}
206
204
fmt .Printf ("write %v files successful" , count )
207
205
}
208
206
209
- func loadMetaData (filePath string ) (map [int ]m. TagList , error ) {
207
+ func loadMetaData (filePath string ) (map [int ]TagList , error ) {
210
208
f , err := os .OpenFile (filePath , os .O_RDONLY , 0644 )
211
209
if err != nil {
212
210
return nil , err
213
211
}
214
212
defer f .Close ()
215
- reader , metaMap := bufio .NewReader (f ), map [int ]m. TagList {}
213
+ reader , metaMap := bufio .NewReader (f ), map [int ]TagList {}
216
214
217
215
for {
218
216
line , _ , err := reader .ReadLine ()
@@ -225,7 +223,7 @@ func loadMetaData(filePath string) (map[int]m.TagList, error) {
225
223
s := strings .Split (string (line ), "|" )
226
224
v , _ := strconv .Atoi (strings .Split (s [1 ], "." )[0 ])
227
225
// v[0] 是题号,s[4] time, s[5] space, s[6] favorite
228
- metaMap [v ] = m. TagList {
226
+ metaMap [v ] = TagList {
229
227
FrontendQuestionID : int32 (v ),
230
228
Acceptance : "" ,
231
229
Difficulty : "" ,
@@ -236,7 +234,7 @@ func loadMetaData(filePath string) (map[int]m.TagList, error) {
236
234
}
237
235
}
238
236
239
- func renderChapterTwo (filePath string , tls m. TagLists ) ([]byte , error ) {
237
+ func renderChapterTwo (filePath string , tls TagLists ) ([]byte , error ) {
240
238
f , err := os .OpenFile (filePath , os .O_RDONLY , 0644 )
241
239
if err != nil {
242
240
return nil , err
@@ -272,18 +270,18 @@ func buildBookMenu() {
272
270
fmt .Println (err )
273
271
return
274
272
}
275
- util . WriteFile ("../website/content/menu/index.md" , res )
273
+ WriteFile ("../website/content/menu/index.md" , res )
276
274
fmt .Println ("generate Menu successful" )
277
275
}
278
276
279
277
// 拷贝 leetcode 目录下的题解 README 文件至第四章对应文件夹中
280
278
func copyLackFile () {
281
- solutionIds , soName , _ := util . LoadSolutionsDir ()
282
- _ , ch4Ids := util . LoadChapterFourDir ()
279
+ solutionIds , soName , _ := LoadSolutionsDir ()
280
+ _ , ch4Ids := LoadChapterFourDir ()
283
281
284
282
needCopy := []string {}
285
283
for i := 0 ; i < len (solutionIds ); i ++ {
286
- if util . BinarySearch (ch4Ids , solutionIds [i ]) == - 1 {
284
+ if BinarySearch (ch4Ids , solutionIds [i ]) == - 1 {
287
285
needCopy = append (needCopy , soName [i ])
288
286
}
289
287
}
@@ -295,12 +293,12 @@ func copyLackFile() {
295
293
if err != nil {
296
294
fmt .Println (err )
297
295
}
298
- err = os .MkdirAll (fmt .Sprintf ("../website/content/ChapterFour/%v" , util . GetChpaterFourFileNum (tmp )), os .ModePerm )
296
+ err = os .MkdirAll (fmt .Sprintf ("../website/content/ChapterFour/%v" , GetChpaterFourFileNum (tmp )), os .ModePerm )
299
297
if err != nil {
300
298
fmt .Println (err )
301
299
}
302
- util . CopyFile (fmt .Sprintf ("../website/content/ChapterFour/%v/%v.md" , util . GetChpaterFourFileNum (tmp ), needCopy [i ]), fmt .Sprintf ("../leetcode/%v/README.md" , needCopy [i ]))
303
- util . CopyFile (fmt .Sprintf ("../website/content/ChapterFour/%v/_index.md" , util . GetChpaterFourFileNum (tmp )), "./template/collapseSection.md" )
300
+ CopyFile (fmt .Sprintf ("../website/content/ChapterFour/%v/%v.md" , GetChpaterFourFileNum (tmp ), needCopy [i ]), fmt .Sprintf ("../leetcode/%v/README.md" , needCopy [i ]))
301
+ CopyFile (fmt .Sprintf ("../website/content/ChapterFour/%v/_index.md" , GetChpaterFourFileNum (tmp )), "./template/collapseSection.md" )
304
302
}
305
303
}
306
304
} else {
0 commit comments