move templates

This commit is contained in:
Celogeek 2023-04-23 12:16:54 +02:00
parent 3ae2489fa5
commit 1ad8f9ddd0
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
3 changed files with 27 additions and 24 deletions

View File

@ -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",

View File

@ -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

View File

@ -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
)