@@ -11,8 +11,6 @@ import (
1111 "strconv"
1212 "strings"
1313
14- m "github.com/halfrost/leetcode-go/ctl/models"
15- "github.com/halfrost/leetcode-go/ctl/util"
1614 "github.com/spf13/cobra"
1715)
1816
@@ -80,13 +78,13 @@ func newBuildMenu() *cobra.Command {
8078
8179func buildREADME () {
8280 var (
83- problems []m. StatStatusPairs
84- lpa m. LeetCodeProblemAll
85- info m. UserInfo
81+ problems []StatStatusPairs
82+ lpa LeetCodeProblemAll
83+ info UserInfo
8684 )
8785 // 请求所有题目信息
8886 body := getProblemAllList ()
89- problemsMap , optimizingIds := map [int ]m. StatStatusPairs {}, []int {}
87+ problemsMap , optimizingIds := map [int ]StatStatusPairs {}, []int {}
9088 err := json .Unmarshal (body , & lpa )
9189 if err != nil {
9290 fmt .Println (err )
@@ -96,30 +94,30 @@ func buildREADME() {
9694
9795 // 拼凑 README 需要渲染的数据
9896 problems = lpa .StatStatusPairs
99- info = m . ConvertUserInfoModel (lpa )
97+ info = ConvertUserInfoModel (lpa )
10098 for _ , v := range problems {
10199 problemsMap [int (v .Stat .FrontendQuestionID )] = v
102100 }
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 )
107105 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 ))
110108
111109 // 按照模板渲染 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 )
113111 if err != nil {
114112 fmt .Println (err )
115113 return
116114 }
117- util . WriteFile ("../README.md" , res )
115+ WriteFile ("../README.md" , res )
118116 fmt .Println ("write file successful" )
119117 //makeReadmeFile(mds)
120118}
121119
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 ) {
123121 f , err := os .OpenFile (filePath , os .O_RDONLY , 0644 )
124122 if err != nil {
125123 return nil , err
@@ -167,8 +165,8 @@ func renderReadme(filePath string, total, try int, mdrows, omdrows m.Mdrows, use
167165// false 渲染的链接是外部 HTTPS 链接,用于生成 PDF
168166func buildChapterTwo (internal bool ) {
169167 var (
170- gr m. GraphQLResp
171- questions []m. Question
168+ gr GraphQLResp
169+ questions []Question
172170 count int
173171 )
174172 for index , tag := range chapterTwoSlug {
@@ -180,39 +178,39 @@ func buildChapterTwo(internal bool) {
180178 return
181179 }
182180 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 ()
186184 tl , err := loadMetaData (fmt .Sprintf ("./meta/%v" , chapterTwoFileName [index ]))
187185 if err != nil {
188186 fmt .Printf ("err = %v\n " , err )
189187 }
190- tls := m . GenerateTagMdRows (solutionIds , tl , mdrows , internal )
188+ tls := GenerateTagMdRows (solutionIds , tl , mdrows , internal )
191189 //fmt.Printf("tls = %v\n", tls)
192190 // 按照模板渲染 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 })
194192 if err != nil {
195193 fmt .Println (err )
196194 return
197195 }
198196 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 )
200198 } else {
201- util . WriteFile (fmt .Sprintf ("./pdftemp/ChapterTwo/%v.md" , chapterTwoFileName [index ]), res )
199+ WriteFile (fmt .Sprintf ("./pdftemp/ChapterTwo/%v.md" , chapterTwoFileName [index ]), res )
202200 }
203201
204202 count ++
205203 }
206204 fmt .Printf ("write %v files successful" , count )
207205}
208206
209- func loadMetaData (filePath string ) (map [int ]m. TagList , error ) {
207+ func loadMetaData (filePath string ) (map [int ]TagList , error ) {
210208 f , err := os .OpenFile (filePath , os .O_RDONLY , 0644 )
211209 if err != nil {
212210 return nil , err
213211 }
214212 defer f .Close ()
215- reader , metaMap := bufio .NewReader (f ), map [int ]m. TagList {}
213+ reader , metaMap := bufio .NewReader (f ), map [int ]TagList {}
216214
217215 for {
218216 line , _ , err := reader .ReadLine ()
@@ -225,7 +223,7 @@ func loadMetaData(filePath string) (map[int]m.TagList, error) {
225223 s := strings .Split (string (line ), "|" )
226224 v , _ := strconv .Atoi (strings .Split (s [1 ], "." )[0 ])
227225 // v[0] 是题号,s[4] time, s[5] space, s[6] favorite
228- metaMap [v ] = m. TagList {
226+ metaMap [v ] = TagList {
229227 FrontendQuestionID : int32 (v ),
230228 Acceptance : "" ,
231229 Difficulty : "" ,
@@ -236,7 +234,7 @@ func loadMetaData(filePath string) (map[int]m.TagList, error) {
236234 }
237235}
238236
239- func renderChapterTwo (filePath string , tls m. TagLists ) ([]byte , error ) {
237+ func renderChapterTwo (filePath string , tls TagLists ) ([]byte , error ) {
240238 f , err := os .OpenFile (filePath , os .O_RDONLY , 0644 )
241239 if err != nil {
242240 return nil , err
@@ -272,18 +270,18 @@ func buildBookMenu() {
272270 fmt .Println (err )
273271 return
274272 }
275- util . WriteFile ("../website/content/menu/index.md" , res )
273+ WriteFile ("../website/content/menu/index.md" , res )
276274 fmt .Println ("generate Menu successful" )
277275}
278276
279277// 拷贝 leetcode 目录下的题解 README 文件至第四章对应文件夹中
280278func copyLackFile () {
281- solutionIds , soName , _ := util . LoadSolutionsDir ()
282- _ , ch4Ids := util . LoadChapterFourDir ()
279+ solutionIds , soName , _ := LoadSolutionsDir ()
280+ _ , ch4Ids := LoadChapterFourDir ()
283281
284282 needCopy := []string {}
285283 for i := 0 ; i < len (solutionIds ); i ++ {
286- if util . BinarySearch (ch4Ids , solutionIds [i ]) == - 1 {
284+ if BinarySearch (ch4Ids , solutionIds [i ]) == - 1 {
287285 needCopy = append (needCopy , soName [i ])
288286 }
289287 }
@@ -295,12 +293,12 @@ func copyLackFile() {
295293 if err != nil {
296294 fmt .Println (err )
297295 }
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 )
299297 if err != nil {
300298 fmt .Println (err )
301299 }
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" )
304302 }
305303 }
306304 } else {
0 commit comments