@@ -30,6 +30,14 @@ tags: [%s]
3030categories: %s
3131---
3232`
33+ HtmlBody = `<html>
34+ <head>
35+ <title>%s</title>
36+ </head>
37+ <body>
38+ %s
39+ </body>
40+ </html>`
3341)
3442
3543var postTime = time .Now ()
@@ -41,6 +49,7 @@ type DetailData struct {
4149type PostDetail struct {
4250 Title string `json:"title"`
4351 Description string `json:"description"`
52+ Content string `json:"content"`
4453 Markdowncontent string `json:"markdowncontent"`
4554 Tags string `json:"tags"`
4655 Categories string `json:"categories"`
@@ -49,7 +58,7 @@ type PostDetail struct {
4958var (
5059 username string
5160 page int
52- cookie string
61+ cookie string
5362 currentPage = 1
5463 count int
5564 wg sync.WaitGroup
5867
5968func init () {
6069 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" )
6271 flag .IntVar (& page , "page" , - 1 , "download pages" )
6372 flag .Parse ()
6473}
@@ -140,12 +149,13 @@ func crawlPostMarkdown(url string) {
140149 }
141150
142151 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 )
144155 }
145156}
146157
147- func buildPost (post PostDetail ) {
148-
158+ func buildMarkdownPost (post PostDetail ) {
149159 date := postTime .Format ("2006-01-02 15:03:04" )
150160 header := fmt .Sprintf (HexoHeader , post .Title , date , post .Tags , post .Categories )
151161
@@ -164,6 +174,21 @@ func buildPost(post PostDetail) {
164174
165175 count ++
166176
177+ defer wg .Done ()
167178 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+
168192 defer wg .Done ()
193+ defer bar .Add ()
169194}
0 commit comments