mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-12 14:41:34 +08:00
Change ctl module level
This commit is contained in:
19
ctl/label.go
19
ctl/label.go
@ -10,7 +10,6 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/halfrost/leetcode-go/ctl/util"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -76,7 +75,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func getChapterFourFileOrder() ([]string, []int) {
|
func getChapterFourFileOrder() ([]string, []int) {
|
||||||
solutions, solutionIds := util.LoadChapterFourDir()
|
solutions, solutionIds := LoadChapterFourDir()
|
||||||
chapterFourFileOrder := []string{"_index"}
|
chapterFourFileOrder := []string{"_index"}
|
||||||
chapterFourFileOrder = append(chapterFourFileOrder, solutions...)
|
chapterFourFileOrder = append(chapterFourFileOrder, solutions...)
|
||||||
fmt.Printf("ChapterFour 中包括 _index 有 %v 个文件, len(id) = %v\n", len(chapterFourFileOrder), len(solutionIds))
|
fmt.Printf("ChapterFour 中包括 _index 有 %v 个文件, len(id) = %v\n", len(chapterFourFileOrder), len(solutionIds))
|
||||||
@ -150,7 +149,7 @@ func addPreNextLabel(order, preOrder []string, chapterFourIds []int, preChapter,
|
|||||||
tmp = "\n\n" + delLine + fmt.Sprintf("<p align = \"right\"><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">下一页➡️</a></p>\n", chapter, order[index+1])
|
tmp = "\n\n" + delLine + fmt.Sprintf("<p align = \"right\"><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">下一页➡️</a></p>\n", chapter, order[index+1])
|
||||||
} else {
|
} else {
|
||||||
if chapter == "ChapterFour" {
|
if chapter == "ChapterFour" {
|
||||||
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">⬅️上一章</a></p>\n", preChapter, preOrder[len(preOrder)-1]) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/%v/\">下一页➡️</a></p>\n", chapter, util.GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter
|
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">⬅️上一章</a></p>\n", preChapter, preOrder[len(preOrder)-1]) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/%v/\">下一页➡️</a></p>\n", chapter, GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter
|
||||||
} else {
|
} else {
|
||||||
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">⬅️上一章</a></p>\n", preChapter, preOrder[len(preOrder)-1]) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">下一页➡️</a></p>\n", chapter, order[index+1]) + preNextFotter
|
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">⬅️上一章</a></p>\n", preChapter, preOrder[len(preOrder)-1]) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">下一页➡️</a></p>\n", chapter, order[index+1]) + preNextFotter
|
||||||
}
|
}
|
||||||
@ -158,26 +157,26 @@ func addPreNextLabel(order, preOrder []string, chapterFourIds []int, preChapter,
|
|||||||
} else if index == len(order)-1 {
|
} else if index == len(order)-1 {
|
||||||
if chapter == "ChapterFour" {
|
if chapter == "ChapterFour" {
|
||||||
// 最后一页不需要“下一页”
|
// 最后一页不需要“下一页”
|
||||||
tmp = "\n\n" + delLine + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/%v/\">⬅️上一页</a></p>\n", chapter, util.GetChpaterFourFileNum(chapterFourIds[(index-1)-1]), order[index-1])
|
tmp = "\n\n" + delLine + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/%v/\">⬅️上一页</a></p>\n", chapter, GetChpaterFourFileNum(chapterFourIds[(index-1)-1]), order[index-1])
|
||||||
} else {
|
} else {
|
||||||
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">⬅️上一页</a></p>\n", chapter, order[index-1]) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/\">下一章➡️</a></p>\n", nextChapter) + preNextFotter
|
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">⬅️上一页</a></p>\n", chapter, order[index-1]) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/\">下一章➡️</a></p>\n", nextChapter) + preNextFotter
|
||||||
}
|
}
|
||||||
} else if index == 1 {
|
} else if index == 1 {
|
||||||
if chapter == "ChapterFour" {
|
if chapter == "ChapterFour" {
|
||||||
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/\">⬅️上一页</a></p>\n", chapter) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/%v/\">下一页➡️</a></p>\n", chapter, util.GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter
|
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/\">⬅️上一页</a></p>\n", chapter) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/%v/\">下一页➡️</a></p>\n", chapter, GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter
|
||||||
} else {
|
} else {
|
||||||
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/\">⬅️上一页</a></p>\n", chapter) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">下一页➡️</a></p>\n", chapter, order[index+1]) + preNextFotter
|
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/\">⬅️上一页</a></p>\n", chapter) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">下一页➡️</a></p>\n", chapter, order[index+1]) + preNextFotter
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if chapter == "ChapterFour" {
|
if chapter == "ChapterFour" {
|
||||||
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/%v/\">⬅️上一页</a></p>\n", chapter, util.GetChpaterFourFileNum(chapterFourIds[(index-1)-1]), order[index-1]) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/%v/\">下一页➡️</a></p>\n", chapter, util.GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter
|
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/%v/\">⬅️上一页</a></p>\n", chapter, GetChpaterFourFileNum(chapterFourIds[(index-1)-1]), order[index-1]) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/%v/\">下一页➡️</a></p>\n", chapter, GetChpaterFourFileNum(chapterFourIds[(index-1)+1]), order[index+1]) + preNextFotter
|
||||||
} else {
|
} else {
|
||||||
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">⬅️上一页</a></p>\n", chapter, order[index-1]) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">下一页➡️</a></p>\n", chapter, order[index+1]) + preNextFotter
|
tmp = "\n\n" + preNextHeader + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">⬅️上一页</a></p>\n", chapter, order[index-1]) + fmt.Sprintf("<p><a href=\"https://books.halfrost.com/leetcode/%v/%v/\">下一页➡️</a></p>\n", chapter, order[index+1]) + preNextFotter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if chapter == "ChapterFour" && index > 0 {
|
if chapter == "ChapterFour" && index > 0 {
|
||||||
path = fmt.Sprintf("%v/%v", util.GetChpaterFourFileNum(chapterFourIds[(index-1)]), path)
|
path = fmt.Sprintf("%v/%v", GetChpaterFourFileNum(chapterFourIds[(index-1)]), path)
|
||||||
}
|
}
|
||||||
|
|
||||||
exist, err = needAdd(fmt.Sprintf("../website/content/%v/%v.md", chapter, path))
|
exist, err = needAdd(fmt.Sprintf("../website/content/%v/%v.md", chapter, path))
|
||||||
@ -192,7 +191,7 @@ func addPreNextLabel(order, preOrder []string, chapterFourIds []int, preChapter,
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.WriteFile(fmt.Sprintf("../website/content/%v/%v.md", chapter, path), res)
|
WriteFile(fmt.Sprintf("../website/content/%v/%v.md", chapter, path), res)
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,7 +241,7 @@ func delPreNextLabel(order []string, chapterFourIds []int, chapter string) {
|
|||||||
lineNum = 3
|
lineNum = 3
|
||||||
}
|
}
|
||||||
if chapter == "ChapterFour" && index > 0 {
|
if chapter == "ChapterFour" && index > 0 {
|
||||||
path = fmt.Sprintf("%v/%v", util.GetChpaterFourFileNum(chapterFourIds[(index-1)]), path)
|
path = fmt.Sprintf("%v/%v", GetChpaterFourFileNum(chapterFourIds[(index-1)]), path)
|
||||||
}
|
}
|
||||||
|
|
||||||
exist, err := needAdd(fmt.Sprintf("../website/content/%v/%v.md", chapter, path))
|
exist, err := needAdd(fmt.Sprintf("../website/content/%v/%v.md", chapter, path))
|
||||||
@ -263,7 +262,7 @@ func delPreNextLabel(order []string, chapterFourIds []int, chapter string) {
|
|||||||
// fmt.Println(err)
|
// fmt.Println(err)
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
// util.WriteFile(fmt.Sprintf("../website/content/ChapterOne/%v.md", v), res)
|
// WriteFile(fmt.Sprintf("../website/content/ChapterOne/%v.md", v), res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func needAdd(filePath string) (bool, error) {
|
func needAdd(filePath string) (bool, error) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package models
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package models
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,7 +0,0 @@
|
|||||||
module github.com/halfrost/LeetCode-Go/ctl/models
|
|
||||||
|
|
||||||
go 1.19
|
|
||||||
|
|
||||||
replace github.com/halfrost/LeetCode-Go/ctl/util => ../util // indirect
|
|
||||||
|
|
||||||
require github.com/halfrost/LeetCode-Go/ctl/util v0.0.0-20220910195543-403dd2823892 // indirect
|
|
15
ctl/pdf.go
15
ctl/pdf.go
@ -10,7 +10,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/halfrost/leetcode-go/ctl/util"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -61,7 +60,7 @@ func generatePDF() {
|
|||||||
// 先删除 pre-next
|
// 先删除 pre-next
|
||||||
delPreNext()
|
delPreNext()
|
||||||
|
|
||||||
chapterFourFileOrder, _ := util.LoadChapterFourDir()
|
chapterFourFileOrder, _ := LoadChapterFourDir()
|
||||||
totalSolutions = len(chapterFourFileOrder)
|
totalSolutions = len(chapterFourFileOrder)
|
||||||
midVersion = totalSolutions / 100
|
midVersion = totalSolutions / 100
|
||||||
lastVersion = totalSolutions % 100
|
lastVersion = totalSolutions % 100
|
||||||
@ -80,7 +79,7 @@ func generatePDF() {
|
|||||||
tmp, err = loadChapter(chapterThreeFileOrder, "./pdftemp", "ChapterThree")
|
tmp, err = loadChapter(chapterThreeFileOrder, "./pdftemp", "ChapterThree")
|
||||||
pdf = append(pdf, tmp...)
|
pdf = append(pdf, tmp...)
|
||||||
// PDF 第四章
|
// PDF 第四章
|
||||||
tmp, err = util.LoadFile("./pdftemp/ChapterFour/_index.md")
|
tmp, err = LoadFile("./pdftemp/ChapterFour/_index.md")
|
||||||
pdf = append(pdf, tmp...)
|
pdf = append(pdf, tmp...)
|
||||||
tmp, err = loadChapter(chapterFourFileOrder, "../website/content", "ChapterFour")
|
tmp, err = loadChapter(chapterFourFileOrder, "../website/content", "ChapterFour")
|
||||||
pdf = append(pdf, tmp...)
|
pdf = append(pdf, tmp...)
|
||||||
@ -88,10 +87,10 @@ func generatePDF() {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
// 生成 PDF
|
// 生成 PDF
|
||||||
util.WriteFile(fmt.Sprintf("../PDF v%v.%v.%v.md", majorVersion, midVersion, lastVersion), pdf)
|
WriteFile(fmt.Sprintf("../PDF v%v.%v.%v.md", majorVersion, midVersion, lastVersion), pdf)
|
||||||
// 还原现场
|
// 还原现场
|
||||||
addPreNext()
|
addPreNext()
|
||||||
util.DestoryDir("./pdftemp")
|
DestoryDir("./pdftemp")
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadChapter(order []string, path, chapter string) ([]byte, error) {
|
func loadChapter(order []string, path, chapter string) ([]byte, error) {
|
||||||
@ -110,10 +109,10 @@ func loadChapter(order []string, path, chapter string) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
tmp, err = util.LoadFile(fmt.Sprintf("%v/%v/%v/%v.md", path, chapter, util.GetChpaterFourFileNum(num), v))
|
tmp, err = LoadFile(fmt.Sprintf("%v/%v/%v/%v.md", path, chapter, GetChpaterFourFileNum(num), v))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tmp, err = util.LoadFile(fmt.Sprintf("%v/%v/%v.md", path, chapter, v))
|
tmp, err = LoadFile(fmt.Sprintf("%v/%v/%v.md", path, chapter, v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -147,7 +146,7 @@ func prepare(path string) {
|
|||||||
}
|
}
|
||||||
// 生成外部链接的 ChapterTwo
|
// 生成外部链接的 ChapterTwo
|
||||||
buildChapterTwo(false)
|
buildChapterTwo(false)
|
||||||
util.CopyFile("./pdftemp/ChapterTwo/_index.md", "../website/content/ChapterTwo/_index.md")
|
CopyFile("./pdftemp/ChapterTwo/_index.md", "../website/content/ChapterTwo/_index.md")
|
||||||
|
|
||||||
for _, v := range chapterTwoFileOrder {
|
for _, v := range chapterTwoFileOrder {
|
||||||
removeHeader(fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", v), fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", v), 5)
|
removeHeader(fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", v), fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", v), 5)
|
||||||
|
@ -11,8 +11,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
m "github.com/halfrost/leetcode-go/ctl/models"
|
|
||||||
"github.com/halfrost/leetcode-go/ctl/util"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,13 +78,13 @@ func newBuildMenu() *cobra.Command {
|
|||||||
|
|
||||||
func buildREADME() {
|
func buildREADME() {
|
||||||
var (
|
var (
|
||||||
problems []m.StatStatusPairs
|
problems []StatStatusPairs
|
||||||
lpa m.LeetCodeProblemAll
|
lpa LeetCodeProblemAll
|
||||||
info m.UserInfo
|
info UserInfo
|
||||||
)
|
)
|
||||||
// 请求所有题目信息
|
// 请求所有题目信息
|
||||||
body := getProblemAllList()
|
body := getProblemAllList()
|
||||||
problemsMap, optimizingIds := map[int]m.StatStatusPairs{}, []int{}
|
problemsMap, optimizingIds := map[int]StatStatusPairs{}, []int{}
|
||||||
err := json.Unmarshal(body, &lpa)
|
err := json.Unmarshal(body, &lpa)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@ -96,30 +94,30 @@ func buildREADME() {
|
|||||||
|
|
||||||
// 拼凑 README 需要渲染的数据
|
// 拼凑 README 需要渲染的数据
|
||||||
problems = lpa.StatStatusPairs
|
problems = lpa.StatStatusPairs
|
||||||
info = m.ConvertUserInfoModel(lpa)
|
info = ConvertUserInfoModel(lpa)
|
||||||
for _, v := range problems {
|
for _, v := range problems {
|
||||||
problemsMap[int(v.Stat.FrontendQuestionID)] = v
|
problemsMap[int(v.Stat.FrontendQuestionID)] = v
|
||||||
}
|
}
|
||||||
mdrows := m.ConvertMdModelFromSsp(problems)
|
mdrows := ConvertMdModelFromSsp(problems)
|
||||||
sort.Sort(m.SortByQuestionID(mdrows))
|
sort.Sort(SortByQuestionID(mdrows))
|
||||||
solutionIds, _, try := util.LoadSolutionsDir()
|
solutionIds, _, try := LoadSolutionsDir()
|
||||||
m.GenerateMdRows(solutionIds, mdrows)
|
GenerateMdRows(solutionIds, mdrows)
|
||||||
info.EasyTotal, info.MediumTotal, info.HardTotal, info.OptimizingEasy, info.OptimizingMedium, info.OptimizingHard, optimizingIds = statisticalData(problemsMap, solutionIds)
|
info.EasyTotal, info.MediumTotal, info.HardTotal, info.OptimizingEasy, info.OptimizingMedium, info.OptimizingHard, optimizingIds = statisticalData(problemsMap, solutionIds)
|
||||||
omdrows := m.ConvertMdModelFromIds(problemsMap, optimizingIds)
|
omdrows := ConvertMdModelFromIds(problemsMap, optimizingIds)
|
||||||
sort.Sort(m.SortByQuestionID(omdrows))
|
sort.Sort(SortByQuestionID(omdrows))
|
||||||
|
|
||||||
// 按照模板渲染 README
|
// 按照模板渲染 README
|
||||||
res, err := renderReadme("./template/template.markdown", len(solutionIds), try, m.Mdrows{Mdrows: mdrows}, m.Mdrows{Mdrows: omdrows}, info)
|
res, err := renderReadme("./template/template.markdown", len(solutionIds), try, Mdrows{Mdrows: mdrows}, Mdrows{Mdrows: omdrows}, info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.WriteFile("../README.md", res)
|
WriteFile("../README.md", res)
|
||||||
fmt.Println("write file successful")
|
fmt.Println("write file successful")
|
||||||
//makeReadmeFile(mds)
|
//makeReadmeFile(mds)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderReadme(filePath string, total, try int, mdrows, omdrows m.Mdrows, user m.UserInfo) ([]byte, error) {
|
func renderReadme(filePath string, total, try int, mdrows, omdrows Mdrows, user UserInfo) ([]byte, error) {
|
||||||
f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
|
f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -167,8 +165,8 @@ func renderReadme(filePath string, total, try int, mdrows, omdrows m.Mdrows, use
|
|||||||
// false 渲染的链接是外部 HTTPS 链接,用于生成 PDF
|
// false 渲染的链接是外部 HTTPS 链接,用于生成 PDF
|
||||||
func buildChapterTwo(internal bool) {
|
func buildChapterTwo(internal bool) {
|
||||||
var (
|
var (
|
||||||
gr m.GraphQLResp
|
gr GraphQLResp
|
||||||
questions []m.Question
|
questions []Question
|
||||||
count int
|
count int
|
||||||
)
|
)
|
||||||
for index, tag := range chapterTwoSlug {
|
for index, tag := range chapterTwoSlug {
|
||||||
@ -180,25 +178,25 @@ func buildChapterTwo(internal bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
questions = gr.Data.TopicTag.Questions
|
questions = gr.Data.TopicTag.Questions
|
||||||
mdrows := m.ConvertMdModelFromQuestions(questions)
|
mdrows := ConvertMdModelFromQuestions(questions)
|
||||||
sort.Sort(m.SortByQuestionID(mdrows))
|
sort.Sort(SortByQuestionID(mdrows))
|
||||||
solutionIds, _, _ := util.LoadSolutionsDir()
|
solutionIds, _, _ := LoadSolutionsDir()
|
||||||
tl, err := loadMetaData(fmt.Sprintf("./meta/%v", chapterTwoFileName[index]))
|
tl, err := loadMetaData(fmt.Sprintf("./meta/%v", chapterTwoFileName[index]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("err = %v\n", err)
|
fmt.Printf("err = %v\n", err)
|
||||||
}
|
}
|
||||||
tls := m.GenerateTagMdRows(solutionIds, tl, mdrows, internal)
|
tls := GenerateTagMdRows(solutionIds, tl, mdrows, internal)
|
||||||
//fmt.Printf("tls = %v\n", tls)
|
//fmt.Printf("tls = %v\n", tls)
|
||||||
// 按照模板渲染 README
|
// 按照模板渲染 README
|
||||||
res, err := renderChapterTwo(fmt.Sprintf("./template/%v.md", chapterTwoFileName[index]), m.TagLists{TagLists: tls})
|
res, err := renderChapterTwo(fmt.Sprintf("./template/%v.md", chapterTwoFileName[index]), TagLists{TagLists: tls})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if internal {
|
if internal {
|
||||||
util.WriteFile(fmt.Sprintf("../website/content/ChapterTwo/%v.md", chapterTwoFileName[index]), res)
|
WriteFile(fmt.Sprintf("../website/content/ChapterTwo/%v.md", chapterTwoFileName[index]), res)
|
||||||
} else {
|
} else {
|
||||||
util.WriteFile(fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", chapterTwoFileName[index]), res)
|
WriteFile(fmt.Sprintf("./pdftemp/ChapterTwo/%v.md", chapterTwoFileName[index]), res)
|
||||||
}
|
}
|
||||||
|
|
||||||
count++
|
count++
|
||||||
@ -206,13 +204,13 @@ func buildChapterTwo(internal bool) {
|
|||||||
fmt.Printf("write %v files successful", count)
|
fmt.Printf("write %v files successful", count)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadMetaData(filePath string) (map[int]m.TagList, error) {
|
func loadMetaData(filePath string) (map[int]TagList, error) {
|
||||||
f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
|
f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
reader, metaMap := bufio.NewReader(f), map[int]m.TagList{}
|
reader, metaMap := bufio.NewReader(f), map[int]TagList{}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
line, _, err := reader.ReadLine()
|
line, _, err := reader.ReadLine()
|
||||||
@ -225,7 +223,7 @@ func loadMetaData(filePath string) (map[int]m.TagList, error) {
|
|||||||
s := strings.Split(string(line), "|")
|
s := strings.Split(string(line), "|")
|
||||||
v, _ := strconv.Atoi(strings.Split(s[1], ".")[0])
|
v, _ := strconv.Atoi(strings.Split(s[1], ".")[0])
|
||||||
// v[0] 是题号,s[4] time, s[5] space, s[6] favorite
|
// v[0] 是题号,s[4] time, s[5] space, s[6] favorite
|
||||||
metaMap[v] = m.TagList{
|
metaMap[v] = TagList{
|
||||||
FrontendQuestionID: int32(v),
|
FrontendQuestionID: int32(v),
|
||||||
Acceptance: "",
|
Acceptance: "",
|
||||||
Difficulty: "",
|
Difficulty: "",
|
||||||
@ -236,7 +234,7 @@ func loadMetaData(filePath string) (map[int]m.TagList, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderChapterTwo(filePath string, tls m.TagLists) ([]byte, error) {
|
func renderChapterTwo(filePath string, tls TagLists) ([]byte, error) {
|
||||||
f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
|
f, err := os.OpenFile(filePath, os.O_RDONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -272,18 +270,18 @@ func buildBookMenu() {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.WriteFile("../website/content/menu/index.md", res)
|
WriteFile("../website/content/menu/index.md", res)
|
||||||
fmt.Println("generate Menu successful")
|
fmt.Println("generate Menu successful")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝 leetcode 目录下的题解 README 文件至第四章对应文件夹中
|
// 拷贝 leetcode 目录下的题解 README 文件至第四章对应文件夹中
|
||||||
func copyLackFile() {
|
func copyLackFile() {
|
||||||
solutionIds, soName, _ := util.LoadSolutionsDir()
|
solutionIds, soName, _ := LoadSolutionsDir()
|
||||||
_, ch4Ids := util.LoadChapterFourDir()
|
_, ch4Ids := LoadChapterFourDir()
|
||||||
|
|
||||||
needCopy := []string{}
|
needCopy := []string{}
|
||||||
for i := 0; i < len(solutionIds); i++ {
|
for i := 0; i < len(solutionIds); i++ {
|
||||||
if util.BinarySearch(ch4Ids, solutionIds[i]) == -1 {
|
if BinarySearch(ch4Ids, solutionIds[i]) == -1 {
|
||||||
needCopy = append(needCopy, soName[i])
|
needCopy = append(needCopy, soName[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,12 +293,12 @@ func copyLackFile() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
err = os.MkdirAll(fmt.Sprintf("../website/content/ChapterFour/%v", util.GetChpaterFourFileNum(tmp)), os.ModePerm)
|
err = os.MkdirAll(fmt.Sprintf("../website/content/ChapterFour/%v", GetChpaterFourFileNum(tmp)), os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
util.CopyFile(fmt.Sprintf("../website/content/ChapterFour/%v/%v.md", util.GetChpaterFourFileNum(tmp), needCopy[i]), fmt.Sprintf("../leetcode/%v/README.md", needCopy[i]))
|
CopyFile(fmt.Sprintf("../website/content/ChapterFour/%v/%v.md", GetChpaterFourFileNum(tmp), needCopy[i]), fmt.Sprintf("../leetcode/%v/README.md", needCopy[i]))
|
||||||
util.CopyFile(fmt.Sprintf("../website/content/ChapterFour/%v/_index.md", util.GetChpaterFourFileNum(tmp)), "./template/collapseSection.md")
|
CopyFile(fmt.Sprintf("../website/content/ChapterFour/%v/_index.md", GetChpaterFourFileNum(tmp)), "./template/collapseSection.md")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -3,9 +3,10 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mozillazg/request"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/mozillazg/request"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -2,19 +2,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
m "github.com/halfrost/leetcode-go/ctl/models"
|
|
||||||
"github.com/halfrost/leetcode-go/ctl/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func statisticalData(problemsMap map[int]m.StatStatusPairs, solutionIds []int) (easyTotal, mediumTotal, hardTotal, optimizingEasy, optimizingMedium, optimizingHard int32, optimizingIds []int) {
|
func statisticalData(problemsMap map[int]StatStatusPairs, solutionIds []int) (easyTotal, mediumTotal, hardTotal, optimizingEasy, optimizingMedium, optimizingHard int32, optimizingIds []int) {
|
||||||
easyTotal, mediumTotal, hardTotal, optimizingEasy, optimizingMedium, optimizingHard, optimizingIds = 0, 0, 0, 0, 0, 0, []int{}
|
easyTotal, mediumTotal, hardTotal, optimizingEasy, optimizingMedium, optimizingHard, optimizingIds = 0, 0, 0, 0, 0, 0, []int{}
|
||||||
for _, v := range problemsMap {
|
for _, v := range problemsMap {
|
||||||
switch m.DifficultyMap[v.Difficulty.Level] {
|
switch DifficultyMap[v.Difficulty.Level] {
|
||||||
case "Easy":
|
case "Easy":
|
||||||
{
|
{
|
||||||
easyTotal++
|
easyTotal++
|
||||||
if v.Status == "ac" && util.BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 {
|
if v.Status == "ac" && BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 {
|
||||||
optimizingEasy++
|
optimizingEasy++
|
||||||
optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID))
|
optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID))
|
||||||
}
|
}
|
||||||
@ -22,7 +19,7 @@ func statisticalData(problemsMap map[int]m.StatStatusPairs, solutionIds []int) (
|
|||||||
case "Medium":
|
case "Medium":
|
||||||
{
|
{
|
||||||
mediumTotal++
|
mediumTotal++
|
||||||
if v.Status == "ac" && util.BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 {
|
if v.Status == "ac" && BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 {
|
||||||
optimizingMedium++
|
optimizingMedium++
|
||||||
optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID))
|
optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID))
|
||||||
}
|
}
|
||||||
@ -30,7 +27,7 @@ func statisticalData(problemsMap map[int]m.StatStatusPairs, solutionIds []int) (
|
|||||||
case "Hard":
|
case "Hard":
|
||||||
{
|
{
|
||||||
hardTotal++
|
hardTotal++
|
||||||
if v.Status == "ac" && util.BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 {
|
if v.Status == "ac" && BinarySearch(solutionIds, int(v.Stat.FrontendQuestionID)) == -1 {
|
||||||
optimizingHard++
|
optimizingHard++
|
||||||
optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID))
|
optimizingIds = append(optimizingIds, int(v.Stat.FrontendQuestionID))
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
package models
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/halfrost/leetcode-go/ctl/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Graphql define
|
// Graphql define
|
||||||
@ -154,15 +152,15 @@ func standardizedTitle(orig string, frontendQuestionID int32) string {
|
|||||||
func GenerateTagMdRows(solutionIds []int, metaMap map[int]TagList, mdrows []Mdrow, internal bool) []TagList {
|
func GenerateTagMdRows(solutionIds []int, metaMap map[int]TagList, mdrows []Mdrow, internal bool) []TagList {
|
||||||
tl := []TagList{}
|
tl := []TagList{}
|
||||||
for _, row := range mdrows {
|
for _, row := range mdrows {
|
||||||
if util.BinarySearch(solutionIds, int(row.FrontendQuestionID)) != -1 {
|
if BinarySearch(solutionIds, int(row.FrontendQuestionID)) != -1 {
|
||||||
tmp := TagList{}
|
tmp := TagList{}
|
||||||
tmp.FrontendQuestionID = row.FrontendQuestionID
|
tmp.FrontendQuestionID = row.FrontendQuestionID
|
||||||
tmp.QuestionTitle = strings.TrimSpace(row.QuestionTitle)
|
tmp.QuestionTitle = strings.TrimSpace(row.QuestionTitle)
|
||||||
s7 := standardizedTitle(row.QuestionTitle, row.FrontendQuestionID)
|
s7 := standardizedTitle(row.QuestionTitle, row.FrontendQuestionID)
|
||||||
if internal {
|
if internal {
|
||||||
tmp.SolutionPath = fmt.Sprintf("[Go]({{< relref \"/ChapterFour/%v/%v.md\" >}})", util.GetChpaterFourFileNum(int(row.FrontendQuestionID)), fmt.Sprintf("%04d.%v", int(row.FrontendQuestionID), s7))
|
tmp.SolutionPath = fmt.Sprintf("[Go]({{< relref \"/ChapterFour/%v/%v.md\" >}})", GetChpaterFourFileNum(int(row.FrontendQuestionID)), fmt.Sprintf("%04d.%v", int(row.FrontendQuestionID), s7))
|
||||||
} else {
|
} else {
|
||||||
tmp.SolutionPath = fmt.Sprintf("[Go](https://books.halfrost.com/leetcode/ChapterFour/%v/%v)", util.GetChpaterFourFileNum(int(row.FrontendQuestionID)), fmt.Sprintf("%04d.%v", int(row.FrontendQuestionID), s7))
|
tmp.SolutionPath = fmt.Sprintf("[Go](https://books.halfrost.com/leetcode/ChapterFour/%v/%v)", GetChpaterFourFileNum(int(row.FrontendQuestionID)), fmt.Sprintf("%04d.%v", int(row.FrontendQuestionID), s7))
|
||||||
}
|
}
|
||||||
tmp.Acceptance = row.Acceptance
|
tmp.Acceptance = row.Acceptance
|
||||||
tmp.Difficulty = row.Difficulty
|
tmp.Difficulty = row.Difficulty
|
@ -6,12 +6,9 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
m "github.com/halfrost/leetcode-go/ctl/models"
|
|
||||||
"github.com/halfrost/leetcode-go/ctl/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeReadmeFile(mdrows m.Mdrows) {
|
func makeReadmeFile(mdrows Mdrows) {
|
||||||
file := "./README.md"
|
file := "./README.md"
|
||||||
os.Remove(file)
|
os.Remove(file)
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
@ -21,7 +18,7 @@ func makeReadmeFile(mdrows m.Mdrows) {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
// 保存 README.md 文件
|
// 保存 README.md 文件
|
||||||
util.WriteFile(file, b.Bytes())
|
WriteFile(file, b.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func readTMPL(path string) string {
|
func readTMPL(path string) string {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package models
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package util
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
@ -1,3 +0,0 @@
|
|||||||
module github.com/halfrost/LeetCode-Go/ctl/util
|
|
||||||
|
|
||||||
go 1.19
|
|
Reference in New Issue
Block a user