@@ -11,6 +11,8 @@ import (
1111 "strconv"
1212 "strings"
1313
14+ m "github.com/halfrost/LeetCode-Go/ctl/models"
15+ "github.com/halfrost/LeetCode-Go/ctl/util"
1416 "github.com/spf13/cobra"
1517)
1618
@@ -78,13 +80,13 @@ func newBuildMenu() *cobra.Command {
7880
7981func buildREADME () {
8082 var (
81- problems []StatStatusPairs
82- lpa LeetCodeProblemAll
83- info UserInfo
83+ problems []m. StatStatusPairs
84+ lpa m. LeetCodeProblemAll
85+ info m. UserInfo
8486 )
8587 // 请求所有题目信息
8688 body := getProblemAllList ()
87- problemsMap , optimizingIds := map [int ]StatStatusPairs {}, []int {}
89+ problemsMap , optimizingIds := map [int ]m. StatStatusPairs {}, []int {}
8890 err := json .Unmarshal (body , & lpa )
8991 if err != nil {
9092 fmt .Println (err )
@@ -94,30 +96,30 @@ func buildREADME() {
9496
9597 // 拼凑 README 需要渲染的数据
9698 problems = lpa .StatStatusPairs
97- info = ConvertUserInfoModel (lpa )
99+ info = m . ConvertUserInfoModel (lpa )
98100 for _ , v := range problems {
99101 problemsMap [int (v .Stat .FrontendQuestionID )] = v
100102 }
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 )
105107 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 ))
108110
109111 // 按照模板渲染 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 )
111113 if err != nil {
112114 fmt .Println (err )
113115 return
114116 }
115- WriteFile ("../README.md" , res )
117+ util . WriteFile ("../README.md" , res )
116118 fmt .Println ("write file successful" )
117119 //makeReadmeFile(mds)
118120}
119121
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 ) {
121123 f , err := os .OpenFile (filePath , os .O_RDONLY , 0644 )
122124 if err != nil {
123125 return nil , err
@@ -165,8 +167,8 @@ func renderReadme(filePath string, total, try int, mdrows, omdrows Mdrows, user
165167// false 渲染的链接是外部 HTTPS 链接,用于生成 PDF
166168func buildChapterTwo (internal bool ) {
167169 var (
168- gr GraphQLResp
169- questions []Question
170+ gr m. GraphQLResp
171+ questions []m. Question
170172 count int
171173 )
172174 for index , tag := range chapterTwoSlug {
@@ -178,39 +180,39 @@ func buildChapterTwo(internal bool) {
178180 return
179181 }
180182 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 ()
184186 tl , err := loadMetaData (fmt .Sprintf ("./meta/%v" , chapterTwoFileName [index ]))
185187 if err != nil {
186188 fmt .Printf ("err = %v\n " , err )
187189 }
188- tls := GenerateTagMdRows (solutionIds , tl , mdrows , internal )
190+ tls := m . GenerateTagMdRows (solutionIds , tl , mdrows , internal )
189191 //fmt.Printf("tls = %v\n", tls)
190192 // 按照模板渲染 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 })
192194 if err != nil {
193195 fmt .Println (err )
194196 return
195197 }
196198 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 )
198200 } else {
199- WriteFile (fmt .Sprintf ("./pdftemp/ChapterTwo/%v.md" , chapterTwoFileName [index ]), res )
201+ util . WriteFile (fmt .Sprintf ("./pdftemp/ChapterTwo/%v.md" , chapterTwoFileName [index ]), res )
200202 }
201203
202204 count ++
203205 }
204206 fmt .Printf ("write %v files successful" , count )
205207}
206208
207- func loadMetaData (filePath string ) (map [int ]TagList , error ) {
209+ func loadMetaData (filePath string ) (map [int ]m. TagList , error ) {
208210 f , err := os .OpenFile (filePath , os .O_RDONLY , 0644 )
209211 if err != nil {
210212 return nil , err
211213 }
212214 defer f .Close ()
213- reader , metaMap := bufio .NewReader (f ), map [int ]TagList {}
215+ reader , metaMap := bufio .NewReader (f ), map [int ]m. TagList {}
214216
215217 for {
216218 line , _ , err := reader .ReadLine ()
@@ -223,7 +225,7 @@ func loadMetaData(filePath string) (map[int]TagList, error) {
223225 s := strings .Split (string (line ), "|" )
224226 v , _ := strconv .Atoi (strings .Split (s [1 ], "." )[0 ])
225227 // v[0] 是题号,s[4] time, s[5] space, s[6] favorite
226- metaMap [v ] = TagList {
228+ metaMap [v ] = m. TagList {
227229 FrontendQuestionID : int32 (v ),
228230 Acceptance : "" ,
229231 Difficulty : "" ,
@@ -234,7 +236,7 @@ func loadMetaData(filePath string) (map[int]TagList, error) {
234236 }
235237}
236238
237- func renderChapterTwo (filePath string , tls TagLists ) ([]byte , error ) {
239+ func renderChapterTwo (filePath string , tls m. TagLists ) ([]byte , error ) {
238240 f , err := os .OpenFile (filePath , os .O_RDONLY , 0644 )
239241 if err != nil {
240242 return nil , err
@@ -270,18 +272,18 @@ func buildBookMenu() {
270272 fmt .Println (err )
271273 return
272274 }
273- WriteFile ("../website/content/menu/index.md" , res )
275+ util . WriteFile ("../website/content/menu/index.md" , res )
274276 fmt .Println ("generate Menu successful" )
275277}
276278
277279// 拷贝 leetcode 目录下的题解 README 文件至第四章对应文件夹中
278280func copyLackFile () {
279- solutionIds , soName , _ := LoadSolutionsDir ()
280- _ , ch4Ids := LoadChapterFourDir ()
281+ solutionIds , soName , _ := util . LoadSolutionsDir ()
282+ _ , ch4Ids := util . LoadChapterFourDir ()
281283
282284 needCopy := []string {}
283285 for i := 0 ; i < len (solutionIds ); i ++ {
284- if BinarySearch (ch4Ids , solutionIds [i ]) == - 1 {
286+ if util . BinarySearch (ch4Ids , solutionIds [i ]) == - 1 {
285287 needCopy = append (needCopy , soName [i ])
286288 }
287289 }
@@ -293,12 +295,12 @@ func copyLackFile() {
293295 if err != nil {
294296 fmt .Println (err )
295297 }
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 )
297299 if err != nil {
298300 fmt .Println (err )
299301 }
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" )
302304 }
303305 }
304306 } else {
0 commit comments