Skip to content

Commit

Permalink
feat: rename directory
Browse files Browse the repository at this point in the history
  • Loading branch information
run-justrun committed Apr 24, 2024
1 parent df59213 commit 3dbf210
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
43 changes: 35 additions & 8 deletions cmd/new/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,27 @@ var (
languageConfigs = map[string]LanguageConfig{
"go": {
LeetcodeLang: "Go",
TplFiles: []TplFile{{"code", "solve_%s.go", codeStrGo}, {"test", "solve_%s_test.go", testCodeStrGo}},
TplFiles: []TplFile{{"code", "%s.%s.go", codeStrGo}, {"test", "%s.%s_test.go", testCodeStrGo}},
},
"ts": {
LeetcodeLang: "TypeScript",
TplFiles: []TplFile{{"code", "solve_%s.ts", codeStrTs}, {"test", "solve_%s.test.ts", testCodeStrTs}},
TplFiles: []TplFile{{"code", "%s.%s.ts", codeStrTs}, {"test", "%s.%s.test.ts", testCodeStrTs}},
},
"js": {
LeetcodeLang: "JavaScript",
TplFiles: []TplFile{{"code", "solve_%s.js", codeStrJs}, {"test", "solve_%s.test.js", testCodeStrJs}},
TplFiles: []TplFile{{"code", "%s.%s.js", codeStrJs}, {"test", "%s.%s.test.js", testCodeStrJs}},
},
"py3": {
LeetcodeLang: "Python3",
TplFiles: []TplFile{{"code", "solve_%s.py", codeStrPy3}, {"test", "test_%s.py", testCodeStrPy3}, {"__init__", "__init__.py", ""}},
TplFiles: []TplFile{{"code", "%s.%s.py", codeStrPy3}, {"test", "%s.%s_test.py", testCodeStrPy3}, {"__init__", "__init__.py", ""}},
},
"java": {
LeetcodeLang: "Java",
TplFiles: []TplFile{{"code", "solve_%s.java", codeStrJava}, {"test", "test_%s.java", testCodeStrJava}},
TplFiles: []TplFile{{"code", "%s.%s.java", codeStrJava}, {"test", "test_%s_%s.java", testCodeStrJava}},
},
"cpp": {
LeetcodeLang: "C++",
TplFiles: []TplFile{{"code", "%s.%s.cpp", codeStrCpp}},
},
}
)
Expand Down Expand Up @@ -103,7 +107,7 @@ func Run(lc *leetcode.Leetcode, n string, lang string) {
log.Fatal(err, meta)
}
number := normalizeNumber(meta.Index)
folderName := prefix + number
folderName := number + "." + meta.Slug
fp := filepath.Join(folder, folderName)
_ = os.MkdirAll(fp, 0755)
metaf := &MetaWithFolder{
Expand All @@ -123,8 +127,8 @@ func Run(lc *leetcode.Leetcode, n string, lang string) {

for _, tpl := range config.TplFiles {
fileName := tpl.FileName
if strings.Count(tpl.FileName, "%s") > 0 {
fileName = fmt.Sprintf(tpl.FileName, number)
if strings.Count(tpl.FileName, "%s") > 1 {
fileName = fmt.Sprintf(tpl.FileName, number, meta.Slug)
}
fp := filepath.Join(fp, fileName)
if !fileExists(fp) {
Expand Down Expand Up @@ -245,3 +249,26 @@ public class test_{{ printf "%04s" .Index }} {
}
`
)

var (
codeStrCpp = `#include <algorithm>
#include <unordered_map>
#include <string>
#include <vector>
#include <iostream>
#include <math.h>
using namespace std;
/**
* @index {{ .Index }}
* @title {{ .Title }}
* @difficulty {{ .Difficulty }}
* @tags {{ .TagStr }}
* @draft false
* @link {{ .Link }}
* @frontendId {{ .FrontendId }}
* @solved {{ .Solved }}
*/
{{ .Code }}
`
)
6 changes: 5 additions & 1 deletion pkg/leetcode/leetcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const RemoteProblems = "https://raw.githubusercontent.com/PPsteven/leetcode-tool
type Meta struct {
Index string
Title string
Slug string
Difficulty string
Tags []string
Link string
Expand Down Expand Up @@ -127,12 +128,15 @@ func (l *Leetcode) getDetail(number string) (*Meta, error) {
title = problem.Get(title).String()
content = problem.Get(content).String()

titleSlug := problem.Get("titleSlug").String()

return &Meta{
Index: number,
Title: title,
Difficulty: difficulty,
Tags: tags,
Link: fmt.Sprintf("%s/problems/%s/description/", host, problem.Get("titleSlug").String()),
Link: fmt.Sprintf("%s/problems/%s/description/", host, titleSlug),
Slug: titleSlug,
Content: content,
}, nil
}
Expand Down

0 comments on commit 3dbf210

Please sign in to comment.