@@ -30,6 +30,14 @@ tags: [%s]
30
30
categories: %s
31
31
---
32
32
`
33
+ HtmlBody = `<html>
34
+ <head>
35
+ <title>%s</title>
36
+ </head>
37
+ <body>
38
+ %s
39
+ </body>
40
+ </html>`
33
41
)
34
42
35
43
var postTime = time .Now ()
@@ -41,6 +49,7 @@ type DetailData struct {
41
49
type PostDetail struct {
42
50
Title string `json:"title"`
43
51
Description string `json:"description"`
52
+ Content string `json:"content"`
44
53
Markdowncontent string `json:"markdowncontent"`
45
54
Tags string `json:"tags"`
46
55
Categories string `json:"categories"`
@@ -49,7 +58,7 @@ type PostDetail struct {
49
58
var (
50
59
username string
51
60
page int
52
- cookie string
61
+ cookie string
53
62
currentPage = 1
54
63
count int
55
64
wg sync.WaitGroup
58
67
59
68
func init () {
60
69
flag .StringVar (& username , "username" , "junmoxi" , "your csdn username" )
61
- flag .StringVar (& cookie , "cookie" , "UserName=junmoxi; UserToken=c3c29cca48be43c4884fe36d052d5852 ;" , "your csdn cookie" )
70
+ flag .StringVar (& cookie , "cookie" , "UserName=junmoxi; UserToken=c3c29cca48be43c4884fe36d052d5851 ;" , "your csdn cookie" )
62
71
flag .IntVar (& page , "page" , - 1 , "download pages" )
63
72
flag .Parse ()
64
73
}
@@ -140,12 +149,13 @@ func crawlPostMarkdown(url string) {
140
149
}
141
150
142
151
if post .Data .Markdowncontent != "" {
143
- go buildPost (post .Data )
152
+ go buildMarkdownPost (post .Data )
153
+ } else if post .Data .Content != "" {
154
+ go buildHtmlPost (post .Data )
144
155
}
145
156
}
146
157
147
- func buildPost (post PostDetail ) {
148
-
158
+ func buildMarkdownPost (post PostDetail ) {
149
159
date := postTime .Format ("2006-01-02 15:03:04" )
150
160
header := fmt .Sprintf (HexoHeader , post .Title , date , post .Tags , post .Categories )
151
161
@@ -164,6 +174,21 @@ func buildPost(post PostDetail) {
164
174
165
175
count ++
166
176
177
+ defer wg .Done ()
167
178
defer bar .Add ()
179
+ }
180
+
181
+ func buildHtmlPost (post PostDetail ) {
182
+
183
+ html := fmt .Sprintf (HtmlBody , post .Title , post .Content )
184
+ err := ioutil .WriteFile (
185
+ fmt .Sprintf ("%s.html" , post .Title ),
186
+ []byte (fmt .Sprintf ("%s" , html )),
187
+ os .ModePerm )
188
+ if err != nil {
189
+ return
190
+ }
191
+
168
192
defer wg .Done ()
193
+ defer bar .Add ()
169
194
}
0 commit comments