-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
64 lines (57 loc) · 1.43 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"os"
"strings"
"github.com/fengxxc/wechatmp2markdown/format"
"github.com/fengxxc/wechatmp2markdown/parse"
"github.com/fengxxc/wechatmp2markdown/server"
)
func main() {
// test.Test1()
// test.Test2()
args := os.Args
if len(args) <= 2 {
panic("not enough args")
}
args1 := args[1]
args2 := args[2]
if args1 == "server" {
// server pattern
port := args2
if port == "" {
port = "8964"
}
server.Start(":" + port)
return
}
// --image=base64 -ib 保存图片,base64格式,在md文件中(默认为此选项)
// --image=url -iu 只保留图片链接
// --image=save -is 保存图片,最终输出到文件夹
// --save=zip -sz 最终打包输出到zip
imageArgValue := "base64"
if len(args) > 3 && args[3] != "" {
if strings.HasPrefix(args[3], "--image=") {
imageArgValue = args[3][len("--image="):]
} else if strings.HasPrefix(args[3], "-i") {
imageArgVal := args[3][len("-i"):]
switch imageArgVal {
case "u":
imageArgValue = "url"
case "s":
imageArgValue = "save"
case "b":
fallthrough
default:
imageArgValue = "base64"
}
}
}
var imagePolicy parse.ImagePolicy = parse.ImageArgValue2ImagePolicy(imageArgValue)
// cli pattern
url := args1
filename := args2
fmt.Printf("url: %s, filename: %s\n", url, filename)
var articleStruct parse.Article = parse.ParseFromURL(url, imagePolicy)
format.FormatAndSave(articleStruct, filename)
}