Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e995641

Browse files
author
kw.lei
committed
add export html
1 parent 5a8bd41 commit e995641

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

‎README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# 批量导出CSDN博客
2-
> 批量导出`csnd`博客,并转化为`hexo`博客样式,只能导出`markdown`编写的博客
2+
> 批量导出`csnd`博客,并转化为`hexo`博客样式,如果你是用富文本编辑器写的则会导出`html`样式
3+
4+
注:有些文章可能获取不到造成进度条无法达到100%,如果走到90%多,走不动了,直接取消即可
35

46
# Quick start
57
```bash

‎main.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ tags: [%s]
3030
categories: %s
3131
---
3232
`
33+
HtmlBody = `<html>
34+
<head>
35+
<title>%s</title>
36+
</head>
37+
<body>
38+
%s
39+
</body>
40+
</html>`
3341
)
3442

3543
var postTime = time.Now()
@@ -41,6 +49,7 @@ type DetailData struct {
4149
type 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 {
4958
var (
5059
username string
5160
page int
52-
cookie string
61+
cookie string
5362
currentPage = 1
5463
count int
5564
wg sync.WaitGroup
@@ -58,7 +67,7 @@ var (
5867

5968
func 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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /