add option to strip first directory from toc

This commit is contained in:
Celogeek 2023-04-08 11:27:57 +02:00
parent a24bf0cfc8
commit 0e9ae95df0
Signed by: celogeek
SSH Key Fingerprint: SHA256:njNJLzoLQdbV9PC6ehcruRb0QnEgxABoCYZ+0+aUIYc
4 changed files with 69 additions and 54 deletions

View File

@ -96,6 +96,7 @@ func (c *Converter) InitParse() {
c.AddBoolParam(&c.Options.HasCover, "hascover", c.Options.HasCover, "Has cover. Indicate if your comic have a cover. The first page will be used as a cover and include after the title.")
c.AddBoolParam(&c.Options.AddPanelView, "addpanelview", c.Options.AddPanelView, "Add an embeded panel view. On kindle you may not need this option as it is handled by the kindle.")
c.AddIntParam(&c.Options.LimitMb, "limitmb", c.Options.LimitMb, "Limit size of the ePub: Default nolimit (0), Minimum 20")
c.AddBoolParam(&c.Options.StripFirstDirectoryFromToc, "strip", c.Options.StripFirstDirectoryFromToc, "Strip first directory from the TOC if only 1")
c.AddSection("Default config")
c.AddBoolParam(&c.Options.Show, "show", false, "Show your default parameters")

View File

@ -32,6 +32,7 @@ type Options struct {
HasCover bool `yaml:"has_cover"`
AddPanelView bool `yaml:"add_panel_view"`
LimitMb int `yaml:"limit_mb"`
StripFirstDirectoryFromToc bool `yaml:"strip_first_directory_from_toc"`
// Default Config
Show bool `yaml:"-"`
@ -60,6 +61,7 @@ func New() *Options {
HasCover: true,
AddPanelView: false,
LimitMb: 0,
StripFirstDirectoryFromToc: false,
profiles: profiles.New(),
}
}
@ -137,7 +139,8 @@ func (o *Options) ShowDefault() string {
Manga : %v
HasCover : %v
AddPanelView : %v
LimitMb : %s`,
LimitMb : %s
StripFirstDirectoryFromToc: %v`,
profileDesc,
o.Quality,
o.Crop,
@ -150,6 +153,7 @@ func (o *Options) ShowDefault() string {
o.HasCover,
o.AddPanelView,
limitmb,
o.StripFirstDirectoryFromToc,
)
}

View File

@ -37,6 +37,7 @@ type EpubOptions struct {
Title string
Author string
LimitMb int
StripFirstDirectoryFromToc bool
*ImageOptions
}
@ -166,10 +167,18 @@ func (e *ePub) getToc(title string, images []*Image) ([]byte, error) {
paths[parentPath].Children.Tags = append(paths[parentPath].Children.Tags, part)
}
}
if paths["."].Children == nil {
children := paths["."].Children
if children != nil && e.StripFirstDirectoryFromToc && len(children.Tags) == 1 {
children = children.Tags[0].Children
}
if children == nil {
return []byte{}, nil
}
return xml.MarshalIndent(paths["."].Children.Tags, " ", " ")
return xml.MarshalIndent(children.Tags, " ", " ")
}
func (e *ePub) Write() error {

View File

@ -101,6 +101,7 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
LimitMb: cmd.Options.LimitMb,
Title: cmd.Options.Title,
Author: cmd.Options.Author,
StripFirstDirectoryFromToc: cmd.Options.StripFirstDirectoryFromToc,
ImageOptions: &epub.ImageOptions{
ViewWidth: profile.Width,
ViewHeight: profile.Height,