Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Merge 29bfce9 into 2a8f9fd
Browse files Browse the repository at this point in the history
  • Loading branch information
gonejack committed Apr 10, 2021
2 parents 2a8f9fd + 29bfce9 commit fc63613
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion epub.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -436,7 +438,7 @@ func addMedia(source string, internalFilename string, mediaFileFormat string, me

mediaMap[internalFilename] = source

return filepath.Join(
return path.Join(
"..",
mediaFolderName,
internalFilename,
Expand Down
17 changes: 14 additions & 3 deletions pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
type pkg struct {
xml *pkgRoot
authorMeta *pkgMeta
coverMeta *pkgMeta
modifiedMeta *pkgMeta
}

Expand Down Expand Up @@ -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 <metadata> element
Expand All @@ -107,10 +110,10 @@ type pkgMetadata struct {
// Ex: <dc:title>Your title here</dc:title>
Title string `xml:"dc:title"`
// Ex: <dc:language>en</dc:language>
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 <spine> element
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit fc63613

Please sign in to comment.