mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 16:22:37 +02:00
title page settings
add option to include or not title page 0 = never 1 = always 2 = when the epub is splitted
This commit is contained in:
parent
0de6cc9acd
commit
a54e093844
@ -129,6 +129,7 @@ func (c *Converter) InitParse() {
|
|||||||
c.AddStringParam(&c.Options.Format, "format", c.Options.Format, "Format of output images: jpeg (lossy), png (lossless)")
|
c.AddStringParam(&c.Options.Format, "format", c.Options.Format, "Format of output images: jpeg (lossy), png (lossless)")
|
||||||
c.AddFloatParam(&c.Options.AspectRatio, "aspect-ratio", c.Options.AspectRatio, "Aspect ratio (height/width) of the output\n -1 = same as device\n 0 = same as source\n1.6 = amazon advice for kindle")
|
c.AddFloatParam(&c.Options.AspectRatio, "aspect-ratio", c.Options.AspectRatio, "Aspect ratio (height/width) of the output\n -1 = same as device\n 0 = same as source\n1.6 = amazon advice for kindle")
|
||||||
c.AddBoolParam(&c.Options.PortraitOnly, "portrait-only", c.Options.PortraitOnly, "Portrait only: force orientation to portrait only.")
|
c.AddBoolParam(&c.Options.PortraitOnly, "portrait-only", c.Options.PortraitOnly, "Portrait only: force orientation to portrait only.")
|
||||||
|
c.AddIntParam(&c.Options.TitlePage, "titlepage", c.Options.TitlePage, "Title page\n0 = never\n1 = always\n2 = only if epub is splitted")
|
||||||
|
|
||||||
c.AddSection("Default config")
|
c.AddSection("Default config")
|
||||||
c.AddBoolParam(&c.Options.Show, "show", false, "Show your default parameters")
|
c.AddBoolParam(&c.Options.Show, "show", false, "Show your default parameters")
|
||||||
@ -361,7 +362,12 @@ func (c *Converter) Validate() error {
|
|||||||
|
|
||||||
// Aspect Ratio
|
// Aspect Ratio
|
||||||
if c.Options.AspectRatio < 0 && c.Options.AspectRatio != -1 {
|
if c.Options.AspectRatio < 0 && c.Options.AspectRatio != -1 {
|
||||||
return errors.New("aspect ratio should be: -1, 0, > 0")
|
return errors.New("aspect ratio should be -1, 0 or > 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Title Page
|
||||||
|
if c.Options.TitlePage < 0 || c.Options.TitlePage > 2 {
|
||||||
|
return errors.New("title page should be 0, 1 or 2")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -45,6 +45,7 @@ type Options struct {
|
|||||||
Format string `yaml:"format"`
|
Format string `yaml:"format"`
|
||||||
AspectRatio float64 `yaml:"aspect_ratio"`
|
AspectRatio float64 `yaml:"aspect_ratio"`
|
||||||
PortraitOnly bool `yaml:"portrait_only"`
|
PortraitOnly bool `yaml:"portrait_only"`
|
||||||
|
TitlePage int `yaml:"title_page"`
|
||||||
|
|
||||||
// Default Config
|
// Default Config
|
||||||
Show bool `yaml:"-"`
|
Show bool `yaml:"-"`
|
||||||
@ -87,6 +88,7 @@ func New() *Options {
|
|||||||
ForegroundColor: "000",
|
ForegroundColor: "000",
|
||||||
BackgroundColor: "FFF",
|
BackgroundColor: "FFF",
|
||||||
Format: "jpeg",
|
Format: "jpeg",
|
||||||
|
TitlePage: 1,
|
||||||
profiles: profiles.New(),
|
profiles: profiles.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,6 +169,16 @@ func (o *Options) ShowConfig() string {
|
|||||||
aspectRatio = fmt.Sprintf("1:%0.2f (device)", float64(profile.Height)/float64(profile.Width))
|
aspectRatio = fmt.Sprintf("1:%0.2f (device)", float64(profile.Height)/float64(profile.Width))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
titlePage := ""
|
||||||
|
switch o.TitlePage {
|
||||||
|
case 0:
|
||||||
|
titlePage = "never"
|
||||||
|
case 1:
|
||||||
|
titlePage = "always"
|
||||||
|
case 2:
|
||||||
|
titlePage = "when epub is splitted"
|
||||||
|
}
|
||||||
|
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
for _, v := range []struct {
|
for _, v := range []struct {
|
||||||
Key string
|
Key string
|
||||||
@ -194,6 +206,7 @@ func (o *Options) ShowConfig() string {
|
|||||||
{"Resize", !o.NoResize, true},
|
{"Resize", !o.NoResize, true},
|
||||||
{"Aspect Ratio", aspectRatio, true},
|
{"Aspect Ratio", aspectRatio, true},
|
||||||
{"Portrait Only", o.PortraitOnly, true},
|
{"Portrait Only", o.PortraitOnly, true},
|
||||||
|
{"Title Page", titlePage, true},
|
||||||
} {
|
} {
|
||||||
if v.Condition {
|
if v.Condition {
|
||||||
b.WriteString(fmt.Sprintf("\n %-26s: %v", v.Key, v.Value))
|
b.WriteString(fmt.Sprintf("\n %-26s: %v", v.Key, v.Value))
|
||||||
|
@ -372,6 +372,7 @@ func (e *ePub) Write() error {
|
|||||||
})
|
})
|
||||||
|
|
||||||
e.computeViewPort(epubParts)
|
e.computeViewPort(epubParts)
|
||||||
|
hasTitlePage := e.TitlePage == 1 || (e.TitlePage == 2 && totalParts > 1)
|
||||||
for i, part := range epubParts {
|
for i, part := range epubParts {
|
||||||
ext := filepath.Ext(e.Output)
|
ext := filepath.Ext(e.Output)
|
||||||
suffix := ""
|
suffix := ""
|
||||||
@ -398,6 +399,7 @@ func (e *ePub) Write() error {
|
|||||||
{"META-INF/com.apple.ibooks.display-options.xml", epubtemplates.AppleBooks},
|
{"META-INF/com.apple.ibooks.display-options.xml", epubtemplates.AppleBooks},
|
||||||
{"OEBPS/content.opf", epubtemplates.Content(&epubtemplates.ContentOptions{
|
{"OEBPS/content.opf", epubtemplates.Content(&epubtemplates.ContentOptions{
|
||||||
Title: title,
|
Title: title,
|
||||||
|
HasTitlePage: hasTitlePage,
|
||||||
UID: e.UID,
|
UID: e.UID,
|
||||||
Author: e.Author,
|
Author: e.Author,
|
||||||
Publisher: e.Publisher,
|
Publisher: e.Publisher,
|
||||||
@ -408,7 +410,7 @@ func (e *ePub) Write() error {
|
|||||||
Current: i + 1,
|
Current: i + 1,
|
||||||
Total: totalParts,
|
Total: totalParts,
|
||||||
})},
|
})},
|
||||||
{"OEBPS/toc.xhtml", epubtemplates.Toc(title, e.StripFirstDirectoryFromToc, part.Images)},
|
{"OEBPS/toc.xhtml", epubtemplates.Toc(title, hasTitlePage, e.StripFirstDirectoryFromToc, part.Images)},
|
||||||
{"OEBPS/Text/style.css", e.render(epubtemplates.Style, map[string]any{
|
{"OEBPS/Text/style.css", e.render(epubtemplates.Style, map[string]any{
|
||||||
"View": e.Image.View,
|
"View": e.Image.View,
|
||||||
})},
|
})},
|
||||||
@ -427,8 +429,10 @@ func (e *ePub) Write() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = e.writeTitleImage(wz, part.Cover, title); err != nil {
|
if hasTitlePage {
|
||||||
return err
|
if err = e.writeTitleImage(wz, part.Cover, title); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastImage := part.Images[len(part.Images)-1]
|
lastImage := part.Images[len(part.Images)-1]
|
||||||
|
@ -41,6 +41,7 @@ type Options struct {
|
|||||||
Input string
|
Input string
|
||||||
Output string
|
Output string
|
||||||
Title string
|
Title string
|
||||||
|
TitlePage int
|
||||||
Author string
|
Author string
|
||||||
LimitMb int
|
LimitMb int
|
||||||
StripFirstDirectoryFromToc bool
|
StripFirstDirectoryFromToc bool
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
type ContentOptions struct {
|
type ContentOptions struct {
|
||||||
Title string
|
Title string
|
||||||
|
HasTitlePage bool
|
||||||
UID string
|
UID string
|
||||||
Author string
|
Author string
|
||||||
Publisher string
|
Publisher string
|
||||||
@ -156,14 +157,19 @@ func getManifest(o *ContentOptions) []tag {
|
|||||||
items := []tag{
|
items := []tag{
|
||||||
{"item", tagAttrs{"id": "toc", "href": "toc.xhtml", "properties": "nav", "media-type": "application/xhtml+xml"}, ""},
|
{"item", tagAttrs{"id": "toc", "href": "toc.xhtml", "properties": "nav", "media-type": "application/xhtml+xml"}, ""},
|
||||||
{"item", tagAttrs{"id": "css", "href": "Text/style.css", "media-type": "text/css"}, ""},
|
{"item", tagAttrs{"id": "css", "href": "Text/style.css", "media-type": "text/css"}, ""},
|
||||||
{"item", tagAttrs{"id": "page_title", "href": "Text/title.xhtml", "media-type": "application/xhtml+xml"}, ""},
|
|
||||||
{"item", tagAttrs{"id": "img_title", "href": fmt.Sprintf("Images/title.%s", o.ImageOptions.Format), "media-type": fmt.Sprintf("image/%s", o.ImageOptions.Format)}, ""},
|
|
||||||
{"item", tagAttrs{"id": "page_cover", "href": "Text/cover.xhtml", "media-type": "application/xhtml+xml"}, ""},
|
{"item", tagAttrs{"id": "page_cover", "href": "Text/cover.xhtml", "media-type": "application/xhtml+xml"}, ""},
|
||||||
{"item", tagAttrs{"id": "img_cover", "href": fmt.Sprintf("Images/cover.%s", o.ImageOptions.Format), "media-type": fmt.Sprintf("image/%s", o.ImageOptions.Format)}, ""},
|
{"item", tagAttrs{"id": "img_cover", "href": fmt.Sprintf("Images/cover.%s", o.ImageOptions.Format), "media-type": fmt.Sprintf("image/%s", o.ImageOptions.Format)}, ""},
|
||||||
}
|
}
|
||||||
|
|
||||||
if !o.ImageOptions.View.PortraitOnly {
|
if o.HasTitlePage {
|
||||||
items = append(items, tag{"item", tagAttrs{"id": "space_title", "href": "Text/space_title.xhtml", "media-type": "application/xhtml+xml"}, ""})
|
items = append(items,
|
||||||
|
tag{"item", tagAttrs{"id": "page_title", "href": "Text/title.xhtml", "media-type": "application/xhtml+xml"}, ""},
|
||||||
|
tag{"item", tagAttrs{"id": "img_title", "href": fmt.Sprintf("Images/title.%s", o.ImageOptions.Format), "media-type": fmt.Sprintf("image/%s", o.ImageOptions.Format)}, ""},
|
||||||
|
)
|
||||||
|
|
||||||
|
if !o.ImageOptions.View.PortraitOnly {
|
||||||
|
items = append(items, tag{"item", tagAttrs{"id": "space_title", "href": "Text/space_title.xhtml", "media-type": "application/xhtml+xml"}, ""})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastImage := o.Images[len(o.Images)-1]
|
lastImage := o.Images[len(o.Images)-1]
|
||||||
@ -198,9 +204,12 @@ func getSpineAuto(o *ContentOptions) []tag {
|
|||||||
return fmt.Sprintf("%s layout-blank", getSpread(false))
|
return fmt.Sprintf("%s layout-blank", getSpread(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
spine := []tag{
|
spine := []tag{}
|
||||||
{"itemref", tagAttrs{"idref": "space_title", "properties": getSpreadBlank()}, ""},
|
if o.HasTitlePage {
|
||||||
{"itemref", tagAttrs{"idref": "page_title", "properties": getSpread(false)}, ""},
|
spine = append(spine,
|
||||||
|
tag{"itemref", tagAttrs{"idref": "space_title", "properties": getSpreadBlank()}, ""},
|
||||||
|
tag{"itemref", tagAttrs{"idref": "page_title", "properties": getSpread(false)}, ""},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
for _, img := range o.Images {
|
for _, img := range o.Images {
|
||||||
if img.DoublePage && o.ImageOptions.Manga == isOnTheRight {
|
if img.DoublePage && o.ImageOptions.Manga == isOnTheRight {
|
||||||
@ -230,8 +239,11 @@ func getSpineAuto(o *ContentOptions) []tag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getSpinePortrait(o *ContentOptions) []tag {
|
func getSpinePortrait(o *ContentOptions) []tag {
|
||||||
spine := []tag{
|
spine := []tag{}
|
||||||
{"itemref", tagAttrs{"idref": "page_title"}, ""},
|
if o.HasTitlePage {
|
||||||
|
spine = append(spine,
|
||||||
|
tag{"itemref", tagAttrs{"idref": "page_title"}, ""},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
for _, img := range o.Images {
|
for _, img := range o.Images {
|
||||||
spine = append(spine, tag{
|
spine = append(spine, tag{
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// create toc
|
// create toc
|
||||||
func Toc(title string, stripFirstDirectoryFromToc bool, images []*epubimage.Image) string {
|
func Toc(title string, hasTitle bool, stripFirstDirectoryFromToc bool, images []*epubimage.Image) string {
|
||||||
doc := etree.NewDocument()
|
doc := etree.NewDocument()
|
||||||
doc.CreateProcInst("xml", `version="1.0" encoding="UTF-8"`)
|
doc.CreateProcInst("xml", `version="1.0" encoding="UTF-8"`)
|
||||||
doc.CreateDirective("DOCTYPE html")
|
doc.CreateDirective("DOCTYPE html")
|
||||||
@ -55,7 +55,11 @@ func Toc(title string, stripFirstDirectoryFromToc bool, images []*epubimage.Imag
|
|||||||
|
|
||||||
beginning := etree.NewElement("li")
|
beginning := etree.NewElement("li")
|
||||||
beginningLink := beginning.CreateElement("a")
|
beginningLink := beginning.CreateElement("a")
|
||||||
beginningLink.CreateAttr("href", "Text/title.xhtml")
|
if hasTitle {
|
||||||
|
beginningLink.CreateAttr("href", "Text/title.xhtml")
|
||||||
|
} else {
|
||||||
|
beginningLink.CreateAttr("href", images[0].PagePath())
|
||||||
|
}
|
||||||
beginningLink.CreateText(title)
|
beginningLink.CreateText(title)
|
||||||
ol.InsertChildAt(0, beginning)
|
ol.InsertChildAt(0, beginning)
|
||||||
|
|
||||||
|
1
main.go
1
main.go
@ -105,6 +105,7 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
|
|||||||
Output: cmd.Options.Output,
|
Output: cmd.Options.Output,
|
||||||
LimitMb: cmd.Options.LimitMb,
|
LimitMb: cmd.Options.LimitMb,
|
||||||
Title: cmd.Options.Title,
|
Title: cmd.Options.Title,
|
||||||
|
TitlePage: cmd.Options.TitlePage,
|
||||||
Author: cmd.Options.Author,
|
Author: cmd.Options.Author,
|
||||||
StripFirstDirectoryFromToc: cmd.Options.StripFirstDirectoryFromToc,
|
StripFirstDirectoryFromToc: cmd.Options.StripFirstDirectoryFromToc,
|
||||||
SortPathMode: cmd.Options.SortPathMode,
|
SortPathMode: cmd.Options.SortPathMode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user