diff --git a/internal/epub/core.go b/internal/epub/core.go index 6948360..be44ce9 100644 --- a/internal/epub/core.go +++ b/internal/epub/core.go @@ -56,10 +56,27 @@ func NewEpub(options *EpubOptions) *ePub { panic(err) } + var spreadRight = options.Manga + tmpl := template.New("parser") tmpl.Funcs(template.FuncMap{ "mod": func(i, j int) bool { return i%j == 0 }, "zoom": func(s int, z float32) int { return int(float32(s) * z) }, + "spread": func() (spread string) { + if spreadRight { + spread = "right" + } else { + spread = "left" + } + spreadRight = !spreadRight + return + }, + "spread_blank": func(part int) bool { + if part == 1 && spreadRight == options.Manga { + return true + } + return false + }, }) return &ePub{ @@ -186,13 +203,28 @@ func (e *ePub) Write() error { wz.WriteImage(part.Cover.Data) for _, img := range part.Images { - text := fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part) - if err := wz.WriteFile(text, e.render(textTmpl, map[string]any{ - "Image": img, - "Manga": e.Manga, - })); err != nil { + if err := wz.WriteFile( + fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part), + e.render(textTmpl, map[string]any{ + "Image": img, + "Manga": e.Manga, + }), + ); err != nil { return err } + + if img.Part == 1 { + if err := wz.WriteFile( + fmt.Sprintf("OEBPS/Text/%d_sp.xhtml", img.Id), + e.render(blankTmpl, map[string]any{ + "Info": e, + "Image": img, + }), + ); err != nil { + return err + } + } + if err := wz.WriteImage(img.Data); err != nil { return err } diff --git a/internal/epub/templates.go b/internal/epub/templates.go index 0fb99cb..f0dea83 100644 --- a/internal/epub/templates.go +++ b/internal/epub/templates.go @@ -22,3 +22,6 @@ var partTmpl string //go:embed "templates/text.xhtml.tmpl" var textTmpl string + +//go:embed "templates/blank.xhtml.tmpl" +var blankTmpl string diff --git a/internal/epub/templates/blank.xhtml.tmpl b/internal/epub/templates/blank.xhtml.tmpl new file mode 100644 index 0000000..c6bfadb --- /dev/null +++ b/internal/epub/templates/blank.xhtml.tmpl @@ -0,0 +1,14 @@ + + + + +Page {{ .Image.Id }} Space + + + + +
+

{{ if .Info.Manga }}←{{ else }}→{{ end }}

+
+ + \ No newline at end of file diff --git a/internal/epub/templates/content.opf.tmpl b/internal/epub/templates/content.opf.tmpl index c0bcc9a..a1855cb 100644 --- a/internal/epub/templates/content.opf.tmpl +++ b/internal/epub/templates/content.opf.tmpl @@ -28,21 +28,18 @@ {{ range .Images }} +{{ if eq .Part 1 }} + +{{ end }} {{ end }} -{{ if .Info.Manga }} - - -{{ range $idx, $ := .Images }} - + + +{{ range .Images }} +{{ if spread_blank .Part }} + +{{ end }} + {{ end }} -{{ else }} - - -{{ range $idx, $ := .Images }} - -{{ end }} - -{{ end }}