-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.go
48 lines (45 loc) · 1.07 KB
/
build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"path"
)
func buildProblem(id, basePath string) {
item := getItem(id)
titleSlug := item.Question.TitleSlug
question := getQuestion(titleSlug)
err := createQuestion(basePath, item, question)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("create problem <%s> successfully!\n", question.QuestionTitle)
}
func buildAllProblems() {
// 一键创建所有题目,按难度和类型分文件夹保存
cardSlugs := []string{
"top-interview-questions-easy",
"top-interview-questions-medium",
"top-interview-questions-hard",
}
for _, cardSlug := range cardSlugs {
cardFolder := path.Join("./" + cardSlug)
err := createFolder(cardFolder)
if err != nil {
fmt.Println(err)
return
}
card := getCard(cardSlug)
for _, c := range card.Chapters {
chapter := getChapter(c.Id, cardSlug)
chapterFolder := path.Join(cardFolder +"/"+ chapter.Slug)
err := createFolder(chapterFolder)
if err != nil {
fmt.Println(err)
return
}
for _, item := range chapter.Items {
buildProblem(item.Id, chapterFolder)
}
}
}
}