From 29bfce969abc90a507dbdd6716304a509a0e4da9 Mon Sep 17 00:00:00 2001 From: gonejack Date: Sat, 10 Apr 2021 09:45:29 +0800 Subject: [PATCH] Fix missing thumbnail on MacOS --- epub.go | 4 +++- pkg.go | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/epub.go b/epub.go index 2211feb..b6fc217 100644 --- a/epub.go +++ b/epub.go @@ -32,6 +32,7 @@ import ( "net/http" "net/url" "os" + "path" "path/filepath" "strings" @@ -309,6 +310,7 @@ func (e *Epub) SetCover(internalImagePath string, internalCSSPath string) { } e.cover.imageFilename = filepath.Base(internalImagePath) + e.pkg.setCover(e.cover.imageFilename) // Use default cover stylesheet if one isn't provided if internalCSSPath == "" { @@ -436,7 +438,7 @@ func addMedia(source string, internalFilename string, mediaFileFormat string, me mediaMap[internalFilename] = source - return filepath.Join( + return path.Join( "..", mediaFolderName, internalFilename, diff --git a/pkg.go b/pkg.go index 6bfeb17..345134b 100644 --- a/pkg.go +++ b/pkg.go @@ -44,6 +44,7 @@ const ( type pkg struct { xml *pkgRoot authorMeta *pkgMeta + coverMeta *pkgMeta modifiedMeta *pkgMeta } @@ -98,6 +99,8 @@ type pkgMeta struct { Scheme string `xml:"scheme,attr,omitempty"` ID string `xml:"id,attr,omitempty"` Data string `xml:",chardata"` + Name string `xml:"name,attr,omitempty"` + Content string `xml:"content,attr,omitempty"` } // The element @@ -107,10 +110,10 @@ type pkgMetadata struct { // Ex: Your title here Title string `xml:"dc:title"` // Ex: en - Language string `xml:"dc:language"` + Language string `xml:"dc:language"` Description string `xml:"dc:description,omitempty"` - Creator *pkgCreator - Meta []pkgMeta `xml:"meta"` + Creator *pkgCreator + Meta []pkgMeta `xml:"meta"` } // The element @@ -182,6 +185,14 @@ func (p *pkg) setAuthor(author string) { p.xml.Metadata.Meta = updateMeta(p.xml.Metadata.Meta, p.authorMeta) } +func (p *pkg) setCover(coverRef string) { + p.coverMeta = &pkgMeta{ + Name: "cover", + Content: coverRef, + } + p.xml.Metadata.Meta = updateMeta(p.xml.Metadata.Meta, p.coverMeta) +} + func (p *pkg) setIdentifier(identifier string) { p.xml.Metadata.Identifier.Data = identifier }