add cover image support (#7)

This commit is contained in:
T.v.Dein
2025-10-19 20:39:04 +02:00
committed by GitHub
parent c2abc4ba4d
commit 2c6e81a2c8
7 changed files with 110 additions and 33 deletions

View File

@@ -11,12 +11,15 @@ import (
// Book epub book
type Book struct {
Ncx Ncx `json:"ncx"`
Opf Opf `json:"opf"`
Container Container `json:"-"`
Mimetype string `json:"-"`
Content []Content
fd *zip.ReadCloser
Ncx Ncx `json:"ncx"`
Opf Opf `json:"opf"`
Container Container `json:"-"`
Mimetype string `json:"-"`
Content []Content
fd *zip.ReadCloser
CoverImage []byte
CoverFile string
CoverMediaType string
}
// Open open resource file

View File

@@ -45,8 +45,11 @@ func Open(fn string, dumpxml bool) (*Book, error) {
if err != nil {
return &bk, err
}
}
break
if mf.ID == "cover-image" {
bk.CoverFile = mf.Href
bk.CoverMediaType = mf.MediaType
}
}
@@ -61,13 +64,18 @@ func Open(fn string, dumpxml bool) (*Book, error) {
if err := ct.String(content); err != nil {
return &bk, err
}
bk.Content = append(bk.Content, ct)
if dumpxml {
fmt.Println(string(ct.XML))
}
}
bk.Content = append(bk.Content, ct)
if dumpxml {
fmt.Println(string(ct.XML))
if strings.Contains(file, bk.CoverFile) {
bk.CoverImage = content
}
}
if dumpxml {