From 393bba0266176fcff357c83e7540a08028a6ad9c Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Sun, 5 Mar 2023 00:01:19 +0100 Subject: [PATCH] remove panelview by default, add an option addpanelview On kindle it's better to not add manually the panelview as it will unlock several features: - Animation - Adjust to screen size - Panel View It means, you can still have a panel view, but it's handled by kindle directly. --- README.md | 2 + internal/epub/core.go | 20 +++-- internal/epub/templates.go | 6 ++ internal/epub/templates/content.opf.tmpl | 5 +- internal/epub/templates/panelview.css.tmpl | 73 ++++++++++++++++++ internal/epub/templates/style.css.tmpl | 74 ------------------- internal/epub/templates/text.xhtml.tmpl | 1 + .../epub/templates/textnopanel.xhtml.tmpl | 14 ++++ main.go | 5 ++ 9 files changed, 120 insertions(+), 80 deletions(-) create mode 100644 internal/epub/templates/panelview.css.tmpl create mode 100644 internal/epub/templates/textnopanel.xhtml.tmpl diff --git a/README.md b/README.md index b3726b9..5dc93cc 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,8 @@ The ePub include as a first page: # go-comic-converter -h Usage of go-comic-converter: + -addpanelview + Add an embeded panel view. On kindle you may not need this option as it is handled by the kindle. -author string Author of the epub (default "GO Comic Converter") -auto diff --git a/internal/epub/core.go b/internal/epub/core.go index 36517c2..ae6e1dc 100644 --- a/internal/epub/core.go +++ b/internal/epub/core.go @@ -26,6 +26,7 @@ type ImageOptions struct { NoBlankPage bool Manga bool HasCover bool + AddPanelView bool Workers int } @@ -198,6 +199,9 @@ func (e *ePub) Write() error { "Total": totalParts, })}, } + if e.AddPanelView { + content = append(content, zipContent{"OEBPS/Text/panelview.css", panelViewTmpl}) + } if err = wz.WriteMagic(); err != nil { return err @@ -215,13 +219,19 @@ func (e *ePub) Write() error { } for _, img := range part.Images { - if err := wz.WriteFile( - fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part), - e.render(textTmpl, map[string]any{ + var content string + if e.AddPanelView { + content = e.render(textTmpl, map[string]any{ "Image": img, "Manga": e.Manga, - }), - ); err != nil { + }) + } else { + content = e.render(textNoPanelTmpl, map[string]any{ + "Image": img, + }) + } + + if err := wz.WriteFile(fmt.Sprintf("OEBPS/Text/%d_p%d.xhtml", img.Id, img.Part), content); err != nil { return err } diff --git a/internal/epub/templates.go b/internal/epub/templates.go index f0dea83..ad5f61d 100644 --- a/internal/epub/templates.go +++ b/internal/epub/templates.go @@ -17,11 +17,17 @@ var navTmpl string //go:embed "templates/style.css.tmpl" var styleTmpl string +//go:embed "templates/panelview.css.tmpl" +var panelViewTmpl string + //go:embed "templates/part.xhtml.tmpl" var partTmpl string //go:embed "templates/text.xhtml.tmpl" var textTmpl string +//go:embed "templates/textnopanel.xhtml.tmpl" +var textNoPanelTmpl string + //go:embed "templates/blank.xhtml.tmpl" var blankTmpl string diff --git a/internal/epub/templates/content.opf.tmpl b/internal/epub/templates/content.opf.tmpl index d79a63e..b41fc1f 100644 --- a/internal/epub/templates/content.opf.tmpl +++ b/internal/epub/templates/content.opf.tmpl @@ -24,7 +24,10 @@ - + +{{ if eq $info.AddPanelView true }} + +{{ end }} {{ range .Images }} diff --git a/internal/epub/templates/panelview.css.tmpl b/internal/epub/templates/panelview.css.tmpl new file mode 100644 index 0000000..7972d32 --- /dev/null +++ b/internal/epub/templates/panelview.css.tmpl @@ -0,0 +1,73 @@ +#PV { + position: absolute; + width: 100%; + height: 100%; + top: 0; + left: 0; +} + +#PV-T { + top: 0; + width: 100%; + height: 50%; +} + +#PV-B { + bottom: 0; + width: 100%; + height: 50%; +} + +#PV-L { + left: 0; + width: 49.5%; + height: 100%; + float: left; +} + +#PV-R { + right: 0; + width: 49.5%; + height: 100%; + float: right; +} + +#PV-TL { + top: 0; + left: 0; + width: 49.5%; + height: 50%; + float: left; +} + +#PV-TR { + top: 0; + right: 0; + width: 49.5%; + height: 50%; + float: right; +} + +#PV-BL { + bottom: 0; + left: 0; + width: 49.5%; + height: 50%; + float: left; +} + +#PV-BR { + bottom: 0; + right: 0; + width: 49.5%; + height: 50%; + float: right; +} + +.PV-P { + width: 100%; + height: 100%; + top: 0; + position: absolute; + display: none; +} \ No newline at end of file diff --git a/internal/epub/templates/style.css.tmpl b/internal/epub/templates/style.css.tmpl index 07eb2ce..ff0d852 100644 --- a/internal/epub/templates/style.css.tmpl +++ b/internal/epub/templates/style.css.tmpl @@ -6,78 +6,4 @@ body { display: block; margin: 0; padding: 0; -} - -#PV { - position: absolute; - width: 100%; - height: 100%; - top: 0; - left: 0; -} - -#PV-T { - top: 0; - width: 100%; - height: 50%; -} - -#PV-B { - bottom: 0; - width: 100%; - height: 50%; -} - -#PV-L { - left: 0; - width: 49.5%; - height: 100%; - float: left; -} - -#PV-R { - right: 0; - width: 49.5%; - height: 100%; - float: right; -} - -#PV-TL { - top: 0; - left: 0; - width: 49.5%; - height: 50%; - float: left; -} - -#PV-TR { - top: 0; - right: 0; - width: 49.5%; - height: 50%; - float: right; -} - -#PV-BL { - bottom: 0; - left: 0; - width: 49.5%; - height: 50%; - float: left; -} - -#PV-BR { - bottom: 0; - right: 0; - width: 49.5%; - height: 50%; - float: right; -} - -.PV-P { - width: 100%; - height: 100%; - top: 0; - position: absolute; - display: none; } \ No newline at end of file diff --git a/internal/epub/templates/text.xhtml.tmpl b/internal/epub/templates/text.xhtml.tmpl index 06c4469..f0cf3bd 100644 --- a/internal/epub/templates/text.xhtml.tmpl +++ b/internal/epub/templates/text.xhtml.tmpl @@ -4,6 +4,7 @@ Page {{ .Image.Id }}_p{{ .Image.Part}} + diff --git a/internal/epub/templates/textnopanel.xhtml.tmpl b/internal/epub/templates/textnopanel.xhtml.tmpl new file mode 100644 index 0000000..dc49560 --- /dev/null +++ b/internal/epub/templates/textnopanel.xhtml.tmpl @@ -0,0 +1,14 @@ + + + + +Page {{ .Image.Id }}_p{{ .Image.Part}} + + + + +
+ +
+ + \ No newline at end of file diff --git a/main.go b/main.go index c640a93..4d7478b 100644 --- a/main.go +++ b/main.go @@ -72,6 +72,7 @@ type Option struct { NoBlankPage bool Manga bool NoCover bool + AddPanelView bool Workers int LimitMb int } @@ -108,6 +109,7 @@ Options: NoBlankPage : %v Manga : %v HasCover : %v + AddPanelView : %v LimitMb : %s Workers : %d `, @@ -125,6 +127,7 @@ Options: o.NoBlankPage, o.Manga, !o.NoCover, + o.AddPanelView, limitmb, o.Workers, ) @@ -158,6 +161,7 @@ func main() { flag.BoolVar(&opt.NoBlankPage, "noblankpage", false, "Remove blank pages") flag.BoolVar(&opt.Manga, "manga", false, "Manga mode (right to left)") flag.BoolVar(&opt.NoCover, "nocover", false, "Indicate if your comic doesn't have a cover. The first page will be used as a cover and include after the title.") + flag.BoolVar(&opt.AddPanelView, "addpanelview", false, "Add an embeded panel view. On kindle you may not need this option as it is handled by the kindle.") flag.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit (0), Minimum 20") flag.IntVar(&opt.Workers, "workers", runtime.NumCPU(), "Number of workers") flag.Usage = func() { @@ -266,6 +270,7 @@ func main() { NoBlankPage: opt.NoBlankPage, Manga: opt.Manga, HasCover: !opt.NoCover, + AddPanelView: opt.AddPanelView, Workers: opt.Workers, }, }).Write(); err != nil {