Skip to content

Commit fa04819

Browse files
committed
pack tpls/,fonts/ with go:embed
1 parent 6145f04 commit fa04819

File tree

9 files changed

+55
-714
lines changed

9 files changed

+55
-714
lines changed

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## 更新日志文件
22

3+
2022.08.25 go版本
4+
1. 更新go版本为v1.16+
5+
2. 采用embed模式来内嵌tpls/fonts文件
6+
37
2022.08.21 go版本
48
1. 删除qtgui版本
59
2. 删除http-server

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
# ebookdl 网文下载器,go语言版本
1414

15+
## 编译版本依赖条件
16+
17+
1. go >= 1.16
18+
2. gcc 必须要安装,用于编译 github.com/andlabs/ui库
19+
1520
## 安装方法
1621

1722
```bash

conf/ebdl_conf.ini

-15
This file was deleted.

ebookCover.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/chromedp/cdproto/cdp"
1818
"github.com/chromedp/chromedp"
1919
"github.com/goki/freetype"
20-
"github.com/sndnvaps/ebookdownloader/fonts"
2120
)
2221

2322
const (
@@ -36,15 +35,13 @@ func GenerateCover(this BookInfo) {
3635
}
3736
defer imgfile.Close()
3837

38+
img := image.NewNRGBA(image.Rect(0, 0, 617, 822))
3939

40-
41-
img := image.NewNRGBA(image.Rect(0,0,617,822))
42-
43-
fg,bg := image.Black,image.White
40+
fg, bg := image.Black, image.White
4441

4542
//需要一个ttf字体文件
4643
//fontAbs, _ := filepath.Abs("./fonts/WenQuanYiMicroHei.ttf")
47-
fontBytes := fonts.MustAsset("fonts/WenQuanYiMicroHei.ttf")
44+
fontBytes, _ := fontFS.ReadFile("fonts/WenQuanYiMicroHei.ttf")
4845
if err != nil {
4946
log.Println(err.Error())
5047
}
@@ -54,7 +51,7 @@ func GenerateCover(this BookInfo) {
5451
log.Println(err.Error())
5552
}
5653

57-
draw.Draw(img,img.Bounds(),bg,image.ZP,draw.Src)
54+
draw.Draw(img, img.Bounds(), bg, image.ZP, draw.Src)
5855

5956
f := freetype.NewContext()
6057
f.SetDPI(72)
@@ -77,7 +74,6 @@ func GenerateCover(this BookInfo) {
7774
ptAuthor := freetype.Pt(img.Bounds().Dx()-320, img.Bounds().Dy()-500) //字体出现的位置
7875
f.DrawString(this.Author+" ©著", ptAuthor) //写入小说作者名
7976

80-
8177
err = jpeg.Encode(imgfile, img, &jpeg.Options{Quality: 100})
8278
if err != nil {
8379
fmt.Println(err.Error())
@@ -125,7 +121,7 @@ func (this BookInfo) GetCover() error {
125121
c, _ := chromedp.NewExecAllocator(context.Background(), options...)
126122

127123
// create context
128-
chromeCtx, cancel := chromedp.NewContext(c, chromedp.WithLogf(log.Printf))
124+
chromeCtx, cancel := chromedp.NewContext(c)
129125
// 执行一个空task, 用提前创建Chrome实例
130126
chromedp.Run(chromeCtx, make([]chromedp.Action, 0, 1)...)
131127
timeoutCtx, cancel := context.WithTimeout(chromeCtx, 20*time.Second)

embed.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ebookdownloader
2+
3+
import (
4+
"embed"
5+
)
6+
7+
//go:embed tpls
8+
var templateFS embed.FS
9+
10+
//go:embed fonts
11+
var fontFS embed.FS

fonts/bindata.go

-246
This file was deleted.

go.mod

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
module github.com/sndnvaps/ebookdownloader
22

3-
go 1.13
3+
go 1.17
44

55
require (
66
github.com/Aiicy/htmlquery v0.0.0-20191217151354-e656ce3100dc
77
github.com/Chain-Zhang/pinyin v0.1.3
88
github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e
9-
github.com/antchfx/xpath v1.1.4 // indirect
109
github.com/asdine/storm/v3 v3.1.1
11-
github.com/bmaupin/go-epub v0.10.0 // indirect
1210
github.com/chromedp/cdproto v0.0.0-20201204063249-be40c824ad18
1311
github.com/chromedp/chromedp v0.5.4
1412
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff
@@ -19,6 +17,25 @@ require (
1917
github.com/stretchr/testify v1.6.1
2018
github.com/unknwon/com v1.0.1
2119
go.etcd.io/bbolt v1.3.4
22-
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect
2320
gopkg.in/urfave/cli.v1 v1.20.0
2421
)
22+
23+
require (
24+
github.com/antchfx/xpath v1.1.4 // indirect
25+
github.com/bmaupin/go-epub v0.10.0 // indirect
26+
github.com/chromedp/sysutil v1.0.0 // indirect
27+
github.com/davecgh/go-spew v1.1.1 // indirect
28+
github.com/gobwas/httphead v0.0.0-20200921212729-da3d93bc3c58 // indirect
29+
github.com/gobwas/pool v0.2.1 // indirect
30+
github.com/gobwas/ws v1.0.4 // indirect
31+
github.com/gofrs/uuid v3.1.0+incompatible // indirect
32+
github.com/josharian/intern v1.0.0 // indirect
33+
github.com/mailru/easyjson v0.7.6 // indirect
34+
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
35+
github.com/pmezard/go-difflib v1.0.0 // indirect
36+
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect
37+
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect
38+
golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect
39+
golang.org/x/text v0.3.6 // indirect
40+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
41+
)

mobi.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,23 @@ import (
1010

1111
"github.com/Chain-Zhang/pinyin"
1212
"github.com/unknwon/com"
13-
"github.com/sndnvaps/ebookdownloader/tpls"
1413
)
1514

16-
17-
func bytes2string(in []byte) string {
15+
func bytes2string(in []byte, e error) string {
1816
return string(in)
1917
}
18+
2019
//GenerateMobi 生成mobi格式电子书
2120
func (this BookInfo) GenerateMobi() {
2221
chapters := this.Chapters //章节信息
2322
Volumes := this.Volumes //分卷信息
24-
//tpl_cover := bytes2string(tpls.MustAsset("./tpls/tpl_cover.html")
25-
tplBookToc := bytes2string(tpls.MustAsset("tpls/tpl_book_toc.html"))
26-
tplChapter := bytes2string(tpls.MustAsset("tpls/tpl_chapter.html"))
27-
tplVolume := bytes2string(tpls.MustAsset("tpls/tpl_volume.html"))
28-
tplContent := bytes2string(tpls.MustAsset("tpls/tpl_content.opf"))
29-
tplStyle := bytes2string(tpls.MustAsset("tpls/tpl_style.css"))
30-
tplToc := bytes2string(tpls.MustAsset("tpls/tpl_toc.ncx"))
23+
//tpl_cover := bytes2string(templateFS.ReadFile("./tpls/tpl_cover.html")
24+
tplBookToc := bytes2string(templateFS.ReadFile("tpls/tpl_book_toc.html"))
25+
tplChapter := bytes2string(templateFS.ReadFile("tpls/tpl_chapter.html"))
26+
tplVolume := bytes2string(templateFS.ReadFile("tpls/tpl_volume.html"))
27+
tplContent := bytes2string(templateFS.ReadFile("tpls/tpl_content.opf"))
28+
tplStyle := bytes2string(templateFS.ReadFile("tpls/tpl_style.css"))
29+
tplToc := bytes2string(templateFS.ReadFile("tpls/tpl_toc.ncx"))
3130
//将文件名转换成拼音
3231
strPinyin, _ := pinyin.New(this.Name).Split("-").Mode(pinyin.WithoutTone).Convert()
3332
savepath := "./tmp/" + strPinyin

tpls/bindata.go

-430
This file was deleted.

0 commit comments

Comments
 (0)