From 741728aa2d9805432f8ed35dfec2cabeb7e07522 Mon Sep 17 00:00:00 2001 From: Onelio Date: Fri, 16 Feb 2018 22:32:04 +0100 Subject: [PATCH] Optimized for Windows OS --- pkg.go | 2 ++ toc.go | 2 ++ write.go | 1 + 3 files changed, 5 insertions(+) diff --git a/pkg.go b/pkg.go index e4c1c22..2014bf2 100644 --- a/pkg.go +++ b/pkg.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "path/filepath" "time" + "strings" ) const ( @@ -146,6 +147,7 @@ func newPackage() *pkg { } func (p *pkg) addToManifest(id string, href string, mediaType string, properties string) { + href = strings.Replace(href, "\\", "/", -1) i := &pkgItem{ ID: id, Href: href, diff --git a/toc.go b/toc.go index bab654f..1663291 100644 --- a/toc.go +++ b/toc.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "path/filepath" "strconv" + "strings" ) const ( @@ -148,6 +149,7 @@ func newTocNcxXML() *tocNcxRoot { // Add a section to the TOC (navXML as well as ncxXML) func (t *toc) addSection(index int, title string, relativePath string) { + relativePath = strings.Replace(relativePath, "\\", "/", -1) l := &tocNavItem{ A: tocNavLink{ Href: relativePath, diff --git a/write.go b/write.go index 5212c54..d238f18 100644 --- a/write.go +++ b/write.go @@ -220,6 +220,7 @@ func (e *Epub) writeEpub(tempDir string, destFilePath string) error { // Get the path of the file relative to the folder we're zipping relativePath, err := filepath.Rel(tempDir, path) + relativePath = strings.Replace(relativePath, "\\", "/", -1) if err != nil { // tempDir and path are both internal, so we shouldn't get here panic(fmt.Sprintf("Error closing EPUB file: %s", err))