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