mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-23 23:32:38 +02:00
fix epub3 errors
This commit is contained in:
parent
30f4d20c6a
commit
f794b37c18
4
go.mod
4
go.mod
@ -4,7 +4,7 @@ go 1.19
|
||||
|
||||
require (
|
||||
github.com/gofrs/uuid v3.1.0+incompatible
|
||||
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4
|
||||
github.com/schollz/progressbar/v3 v3.12.2
|
||||
golang.org/x/image v0.2.0
|
||||
)
|
||||
|
||||
@ -12,8 +12,6 @@ require (
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||
github.com/rivo/uniseg v0.4.3 // indirect
|
||||
github.com/schollz/progressbar/v3 v3.12.2 // indirect
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
|
||||
golang.org/x/sys v0.3.0 // indirect
|
||||
golang.org/x/term v0.3.0 // indirect
|
||||
)
|
||||
|
6
go.sum
6
go.sum
@ -1,4 +1,5 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gofrs/uuid v3.1.0+incompatible h1:q2rtkjaKT4YEr6E1kamy0Ha4RtepWlQBedyHx0uzKwA=
|
||||
github.com/gofrs/uuid v3.1.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
@ -8,6 +9,7 @@ github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWV
|
||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
|
||||
@ -15,9 +17,8 @@ github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUc
|
||||
github.com/schollz/progressbar/v3 v3.12.2 h1:yLqqqpQNMxGxHY8uEshRihaHWwa0rf0yb7/Zrpgq2C0=
|
||||
github.com/schollz/progressbar/v3 v3.12.2/go.mod h1:HFJYIYQQJX32UJdyoigUl19xoV6aMwZt6iX/C30RWfg=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 h1:0sw0nJM544SpsihWx1bkXdYLQDlzRflMgFJQ4Yih9ts=
|
||||
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4/go.mod h1:+ccdNT0xMY1dtc5XBxumbYfOUhmduiGudqaDgD2rVRE=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
@ -26,7 +27,6 @@ golang.org/x/image v0.2.0/go.mod h1:la7oBXb9w3YFjBqaAwtynVioc1ZvOnNteUNrifGNmAI=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
"github.com/yosssi/gohtml"
|
||||
|
||||
imageconverter "go-comic-converter/internal/image-converter"
|
||||
)
|
||||
@ -112,6 +111,28 @@ func (e *EPub) SetLimitMb(l int) *EPub {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *EPub) WriteMagic(wz *zip.Writer) error {
|
||||
t := time.Now()
|
||||
fh := &zip.FileHeader{
|
||||
Name: "mimetype",
|
||||
Method: zip.Store,
|
||||
Modified: t,
|
||||
ModifiedTime: uint16(t.Second()/2 + t.Minute()<<5 + t.Hour()<<11),
|
||||
ModifiedDate: uint16(t.Day() + int(t.Month())<<5 + (t.Year()-1980)<<9),
|
||||
CompressedSize64: 20,
|
||||
UncompressedSize64: 20,
|
||||
CRC32: 0x2cab616f,
|
||||
}
|
||||
fh.SetMode(0600)
|
||||
m, err := wz.CreateRaw(fh)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = m.Write([]byte("application/epub+zip"))
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *EPub) WriteFile(wz *zip.Writer, file string, data any) error {
|
||||
var content []byte
|
||||
switch b := data.(type) {
|
||||
@ -126,6 +147,7 @@ func (e *EPub) WriteFile(wz *zip.Writer, file string, data any) error {
|
||||
m, err := wz.CreateHeader(&zip.FileHeader{
|
||||
Name: file,
|
||||
Modified: time.Now(),
|
||||
Method: zip.Deflate,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@ -144,7 +166,7 @@ func (e *EPub) Render(templateString string, data any) string {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return gohtml.Format(result.String())
|
||||
return result.String()
|
||||
}
|
||||
|
||||
func (e *EPub) LoadDir(dirname string) *EPub {
|
||||
@ -283,8 +305,8 @@ func (e *EPub) Write() error {
|
||||
epubParts := e.GetParts()
|
||||
totalParts := len(epubParts)
|
||||
|
||||
bar := progressbar.Default(int64(totalParts), "Writing Part")
|
||||
for i, part := range epubParts {
|
||||
fmt.Printf("Writing part %d...\n", i+1)
|
||||
ext := filepath.Ext(e.Path)
|
||||
suffix := ""
|
||||
if totalParts > 1 {
|
||||
@ -297,10 +319,9 @@ func (e *EPub) Write() error {
|
||||
}
|
||||
|
||||
zipContent := []ZipContent{
|
||||
{"mimetype", TEMPLATE_MIME_TYPE},
|
||||
{"META-INF/container.xml", gohtml.Format(TEMPLATE_CONTAINER)},
|
||||
{"META-INF/container.xml", TEMPLATE_CONTAINER},
|
||||
{"OEBPS/content.opf", e.Render(TEMPLATE_CONTENT, map[string]any{"Info": e, "Images": part.Images})},
|
||||
{"OEBPS/toc.ncx", e.Render(TEMPLATE_TOC, map[string]any{"Info": e, "Images": part.Images})},
|
||||
{"OEBPS/toc.ncx", e.Render(TEMPLATE_TOC, map[string]any{"Info": e, "Image": part.Images[0]})},
|
||||
{"OEBPS/nav.xhtml", e.Render(TEMPLATE_NAV, map[string]any{"Info": e, "Image": part.Images[0]})},
|
||||
{"OEBPS/Text/style.css", TEMPLATE_STYLE},
|
||||
{"OEBPS/Text/part.xhtml", e.Render(TEMPLATE_PART, map[string]any{
|
||||
@ -312,6 +333,11 @@ func (e *EPub) Write() error {
|
||||
}
|
||||
|
||||
wz := zip.NewWriter(w)
|
||||
defer wz.Close()
|
||||
|
||||
if err = e.WriteMagic(wz); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, content := range zipContent {
|
||||
if err := e.WriteFile(wz, content.Name, content.Content); err != nil {
|
||||
return err
|
||||
@ -328,8 +354,9 @@ func (e *EPub) Write() error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
wz.Close()
|
||||
bar.Add(1)
|
||||
}
|
||||
bar.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -2,9 +2,6 @@ package epub
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed "templates/mimetype.tmpl"
|
||||
var TEMPLATE_MIME_TYPE string
|
||||
|
||||
//go:embed "templates/container.xml.tmpl"
|
||||
var TEMPLATE_CONTAINER string
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
|
||||
<item id="nav" href="nav.xhtml" properties="nav" media-type="application/xhtml+xml"/>
|
||||
<item id="cover" href="Images/cover.jpg" media-type="image/jpeg" properties="cover-image"/>
|
||||
<item id="css" href="Text/style.css" media-type="text/css"/>
|
||||
<item id="page_part" href="Text/part.xhtml" media-type="application/xhtml+xml"/>
|
||||
{{ range .Images }}
|
||||
<item id="page_{{ .Id }}" href="Text/{{ .Id }}.xhtml" media-type="application/xhtml+xml"/>
|
||||
|
@ -1 +0,0 @@
|
||||
application/epub+zip
|
@ -8,14 +8,8 @@
|
||||
</head>
|
||||
<body style="">
|
||||
<div style="text-align:center;top:0.0%;">
|
||||
<h1>
|
||||
<p>
|
||||
{{ .Info.Title }}
|
||||
</p>
|
||||
<p>
|
||||
Part {{ .Part }} / {{ .Total }}
|
||||
</p>
|
||||
</h1>
|
||||
<h1>{{ .Info.Title }}</h1>
|
||||
<h1>Part {{ .Part }} / {{ .Total }}</h1>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -9,6 +9,6 @@
|
||||
</head>
|
||||
<docTitle><text>{{ .Info.Title }}</text></docTitle>
|
||||
<navMap>
|
||||
<navPoint id="Text"><navLabel><text>{{ .Info.Title }}</text></navLabel><content src="Text/cover.xhtml"/></navPoint>
|
||||
<navPoint id="Text"><navLabel><text>{{ .Info.Title }}</text></navLabel><content src="Text/{{ .Image.Id }}.xhtml"/></navPoint>
|
||||
</navMap>
|
||||
</ncx>
|
Loading…
x
Reference in New Issue
Block a user