forked from ystyle/kaf-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmobil.go
37 lines (34 loc) · 949 Bytes
/
mobil.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
package kafcli
import (
"fmt"
"github.com/766b/mobi"
"time"
)
type MobiConverter struct{}
func (convert MobiConverter) Build(book Book) error {
fmt.Println("使用第三方库生成mobi, 不保证所有样式都能正常显示")
fmt.Println("正在生成mobi...")
start := time.Now()
m, err := mobi.NewWriter(fmt.Sprintf("%s.mobi", book.Out))
if err != nil {
panic(err)
}
m.Title(book.Bookname)
m.Compression(mobi.CompressionNone)
if book.Cover != "" {
m.AddCover(book.Cover, book.Cover)
}
m.NewExthRecord(mobi.EXTH_DOCTYPE, "EBOK")
m.NewExthRecord(mobi.EXTH_AUTHOR, book.Author)
for _, section := range book.SectionList {
m.NewChapter(section.Title, []byte(section.Content))
if len(section.Sections) > 0 {
for _, subsection := range section.Sections {
m.NewChapter(subsection.Title, []byte(subsection.Content))
}
}
}
m.Write()
fmt.Println("生成mobi电子书耗时:", time.Now().Sub(start))
return nil
}