diff --git a/internal/epub/epub.go b/internal/epub/epub.go index 7c8c0a7..b489c9e 100644 --- a/internal/epub/epub.go +++ b/internal/epub/epub.go @@ -10,6 +10,7 @@ import ( "text/template" "time" + "github.com/celogeek/go-comic-converter/v2/internal/epub/templates" "github.com/gofrs/uuid" ) @@ -97,7 +98,7 @@ func (e *ePub) render(templateString string, data any) string { func (e *ePub) writeImage(wz *epubZip, img *Image) error { err := wz.WriteFile( fmt.Sprintf("OEBPS/%s", img.TextPath()), - e.render(textTmpl, map[string]any{ + e.render(templates.Text, map[string]any{ "Title": fmt.Sprintf("Image %d Part %d", img.Id, img.Part), "ViewPort": fmt.Sprintf("width=%d,height=%d", e.ViewWidth, e.ViewHeight), "ImagePath": img.ImgPath(), @@ -115,7 +116,7 @@ func (e *ePub) writeImage(wz *epubZip, img *Image) error { func (e *ePub) writeBlank(wz *epubZip, img *Image) error { return wz.WriteFile( fmt.Sprintf("OEBPS/Text/%d_sp.xhtml", img.Id), - e.render(blankTmpl, map[string]any{ + e.render(templates.Blank, map[string]any{ "Title": fmt.Sprintf("Blank Page %d", img.Id), "ViewPort": fmt.Sprintf("width=%d,height=%d", e.ViewWidth, e.ViewHeight), }), @@ -241,15 +242,15 @@ func (e *ePub) Write() error { } content := []zipContent{ - {"META-INF/container.xml", containerTmpl}, - {"META-INF/com.apple.ibooks.display-options.xml", appleBooksTmpl}, + {"META-INF/container.xml", templates.Container}, + {"META-INF/com.apple.ibooks.display-options.xml", templates.AppleBooks}, {"OEBPS/content.opf", e.getContent(title, part, i+1, totalParts).String()}, {"OEBPS/toc.xhtml", e.getToc(title, part.Images)}, - {"OEBPS/Text/style.css", e.render(styleTmpl, map[string]any{ + {"OEBPS/Text/style.css", e.render(templates.Style, map[string]any{ "PageWidth": e.ViewWidth, "PageHeight": e.ViewHeight, })}, - {"OEBPS/Text/title.xhtml", e.render(textTmpl, map[string]any{ + {"OEBPS/Text/title.xhtml", e.render(templates.Text, map[string]any{ "Title": title, "ViewPort": fmt.Sprintf("width=%d,height=%d", e.ViewWidth, e.ViewHeight), "ImagePath": "Images/title.jpg", diff --git a/internal/epub/epub_templates.go b/internal/epub/epub_templates.go deleted file mode 100644 index e15e798..0000000 --- a/internal/epub/epub_templates.go +++ /dev/null @@ -1,18 +0,0 @@ -package epub - -import _ "embed" - -//go:embed "templates/epub_templates_container.xml.tmpl" -var containerTmpl string - -//go:embed "templates/epub_templates_applebooks.xml.tmpl" -var appleBooksTmpl string - -//go:embed "templates/epub_templates_style.css.tmpl" -var styleTmpl string - -//go:embed "templates/epub_templates_text.xhtml.tmpl" -var textTmpl string - -//go:embed "templates/epub_templates_blank.xhtml.tmpl" -var blankTmpl string diff --git a/internal/epub/templates/epub_templates.go b/internal/epub/templates/epub_templates.go new file mode 100644 index 0000000..df65026 --- /dev/null +++ b/internal/epub/templates/epub_templates.go @@ -0,0 +1,20 @@ +package templates + +import _ "embed" + +var ( + //go:embed "epub_templates_container.xml.tmpl" + Container string + + //go:embed "epub_templates_applebooks.xml.tmpl" + AppleBooks string + + //go:embed "epub_templates_style.css.tmpl" + Style string + + //go:embed "epub_templates_text.xhtml.tmpl" + Text string + + //go:embed "epub_templates_blank.xhtml.tmpl" + Blank string +)