Skip to content

Commit 3dbf210

Browse files
committed
feat: rename directory
1 parent df59213 commit 3dbf210

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

cmd/new/main.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,27 @@ var (
3333
languageConfigs = map[string]LanguageConfig{
3434
"go": {
3535
LeetcodeLang: "Go",
36-
TplFiles: []TplFile{{"code", "solve_%s.go", codeStrGo}, {"test", "solve_%s_test.go", testCodeStrGo}},
36+
TplFiles: []TplFile{{"code", "%s.%s.go", codeStrGo}, {"test", "%s.%s_test.go", testCodeStrGo}},
3737
},
3838
"ts": {
3939
LeetcodeLang: "TypeScript",
40-
TplFiles: []TplFile{{"code", "solve_%s.ts", codeStrTs}, {"test", "solve_%s.test.ts", testCodeStrTs}},
40+
TplFiles: []TplFile{{"code", "%s.%s.ts", codeStrTs}, {"test", "%s.%s.test.ts", testCodeStrTs}},
4141
},
4242
"js": {
4343
LeetcodeLang: "JavaScript",
44-
TplFiles: []TplFile{{"code", "solve_%s.js", codeStrJs}, {"test", "solve_%s.test.js", testCodeStrJs}},
44+
TplFiles: []TplFile{{"code", "%s.%s.js", codeStrJs}, {"test", "%s.%s.test.js", testCodeStrJs}},
4545
},
4646
"py3": {
4747
LeetcodeLang: "Python3",
48-
TplFiles: []TplFile{{"code", "solve_%s.py", codeStrPy3}, {"test", "test_%s.py", testCodeStrPy3}, {"__init__", "__init__.py", ""}},
48+
TplFiles: []TplFile{{"code", "%s.%s.py", codeStrPy3}, {"test", "%s.%s_test.py", testCodeStrPy3}, {"__init__", "__init__.py", ""}},
4949
},
5050
"java": {
5151
LeetcodeLang: "Java",
52-
TplFiles: []TplFile{{"code", "solve_%s.java", codeStrJava}, {"test", "test_%s.java", testCodeStrJava}},
52+
TplFiles: []TplFile{{"code", "%s.%s.java", codeStrJava}, {"test", "test_%s_%s.java", testCodeStrJava}},
53+
},
54+
"cpp": {
55+
LeetcodeLang: "C++",
56+
TplFiles: []TplFile{{"code", "%s.%s.cpp", codeStrCpp}},
5357
},
5458
}
5559
)
@@ -103,7 +107,7 @@ func Run(lc *leetcode.Leetcode, n string, lang string) {
103107
log.Fatal(err, meta)
104108
}
105109
number := normalizeNumber(meta.Index)
106-
folderName := prefix + number
110+
folderName := number + "." + meta.Slug
107111
fp := filepath.Join(folder, folderName)
108112
_ = os.MkdirAll(fp, 0755)
109113
metaf := &MetaWithFolder{
@@ -123,8 +127,8 @@ func Run(lc *leetcode.Leetcode, n string, lang string) {
123127

124128
for _, tpl := range config.TplFiles {
125129
fileName := tpl.FileName
126-
if strings.Count(tpl.FileName, "%s") > 0 {
127-
fileName = fmt.Sprintf(tpl.FileName, number)
130+
if strings.Count(tpl.FileName, "%s") > 1 {
131+
fileName = fmt.Sprintf(tpl.FileName, number, meta.Slug)
128132
}
129133
fp := filepath.Join(fp, fileName)
130134
if !fileExists(fp) {
@@ -245,3 +249,26 @@ public class test_{{ printf "%04s" .Index }} {
245249
}
246250
`
247251
)
252+
253+
var (
254+
codeStrCpp = `#include <algorithm>
255+
#include <unordered_map>
256+
#include <string>
257+
#include <vector>
258+
#include <iostream>
259+
#include <math.h>
260+
using namespace std;
261+
262+
/**
263+
* @index {{ .Index }}
264+
* @title {{ .Title }}
265+
* @difficulty {{ .Difficulty }}
266+
* @tags {{ .TagStr }}
267+
* @draft false
268+
* @link {{ .Link }}
269+
* @frontendId {{ .FrontendId }}
270+
* @solved {{ .Solved }}
271+
*/
272+
{{ .Code }}
273+
`
274+
)

pkg/leetcode/leetcode.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const RemoteProblems = "https://raw.githubusercontent.com/PPsteven/leetcode-tool
2121
type Meta struct {
2222
Index string
2323
Title string
24+
Slug string
2425
Difficulty string
2526
Tags []string
2627
Link string
@@ -127,12 +128,15 @@ func (l *Leetcode) getDetail(number string) (*Meta, error) {
127128
title = problem.Get(title).String()
128129
content = problem.Get(content).String()
129130

131+
titleSlug := problem.Get("titleSlug").String()
132+
130133
return &Meta{
131134
Index: number,
132135
Title: title,
133136
Difficulty: difficulty,
134137
Tags: tags,
135-
Link: fmt.Sprintf("%s/problems/%s/description/", host, problem.Get("titleSlug").String()),
138+
Link: fmt.Sprintf("%s/problems/%s/description/", host, titleSlug),
139+
Slug: titleSlug,
136140
Content: content,
137141
}, nil
138142
}

0 commit comments

Comments
 (0)