Skip to content

Commit ffecbb1

Browse files
author
Shuo
authored
Merge pull request #535 from openset/develop
Add: CmdPost
2 parents 234ef2c + 84de14d commit ffecbb1

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

internal/post/post.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package post
33
import (
44
"bytes"
55
"fmt"
6+
"os"
67
"path"
78
"regexp"
89
"strconv"
@@ -18,6 +19,7 @@ var CmdPost = &base.Command{
1819
UsageLine: "post",
1920
Short: "build post files",
2021
Long: "build all post files.",
22+
Hidden: true,
2123
}
2224

2325
func runPost(cmd *base.Command, args []string) {
@@ -77,7 +79,11 @@ func runPost(cmd *base.Command, args []string) {
7779
buf.WriteString("\n---\n")
7880
buf.WriteString(fmt.Sprintf("\n## [答案](https://github.com/openset/leetcode/tree/master/problems/%s)\n", question.TitleSlug))
7981
filename := fmt.Sprintf(formatFilename, t.Format("2006-01-02"), question.TitleSlug)
80-
base.FilePutContents(path.Join("post", filename), buf.Bytes())
82+
postType := "leetcode"
83+
if inPosts[questionId] {
84+
postType = "_posts"
85+
}
86+
base.FilePutContents(path.Join(basePath, postType, filename), buf.Bytes())
8187
}
8288
}
8389
postTags()
@@ -91,7 +97,7 @@ func postTags() {
9197
}
9298
filename := fmt.Sprintf("tag-%s.md", tag.Slug)
9399
data := []byte(fmt.Sprintf(tagTmpl, title, tag.Slug, tag.Name))
94-
base.FilePutContents(path.Join("page", filename), data)
100+
base.FilePutContents(path.Join(basePath, "_pages", filename), data)
95101
}
96102
}
97103

@@ -112,3 +118,37 @@ permalink: /tags/%s/
112118
taxonomy: %s
113119
---
114120
`
121+
122+
var homeDir, _ = os.UserHomeDir()
123+
124+
var basePath = path.Join(homeDir, "openset", "openset")
125+
126+
var inPosts = map[int]bool{
127+
1: true,
128+
2: true,
129+
3: true,
130+
4: true,
131+
7: true,
132+
8: true,
133+
9: true,
134+
12: true,
135+
13: true,
136+
15: true,
137+
18: true,
138+
20: true,
139+
58: true,
140+
101: true,
141+
168: true,
142+
171: true,
143+
172: true,
144+
190: true,
145+
191: true,
146+
198: true,
147+
233: true,
148+
746: true,
149+
793: true,
150+
849: true,
151+
941: true,
152+
984: true,
153+
1000: true,
154+
}

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/openset/leetcode/internal/helper"
1313
"github.com/openset/leetcode/internal/open"
1414
"github.com/openset/leetcode/internal/page"
15+
"github.com/openset/leetcode/internal/post"
1516
"github.com/openset/leetcode/internal/question"
1617
"github.com/openset/leetcode/internal/readme"
1718
"github.com/openset/leetcode/internal/tag"
@@ -34,6 +35,7 @@ func init() {
3435
clean.CmdClean,
3536
version.CmdVersion,
3637
help.CmdHelp,
38+
post.CmdPost,
3739
}
3840
}
3941

0 commit comments

Comments
 (0)