diff --git a/internal/converter/core.go b/internal/converter/core.go index 5fa42b5..e02cdca 100644 --- a/internal/converter/core.go +++ b/internal/converter/core.go @@ -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") diff --git a/internal/converter/options/core.go b/internal/converter/options/core.go index 26cc750..f5d27c9 100644 --- a/internal/converter/options/core.go +++ b/internal/converter/options/core.go @@ -20,18 +20,19 @@ type Options struct { Dry bool `yaml:"-"` // Config - Profile string `yaml:"profile"` - Quality int `yaml:"quality"` - Crop bool `yaml:"crop"` - Brightness int `yaml:"brightness"` - Contrast int `yaml:"contrast"` - AutoRotate bool `yaml:"auto_rotate"` - AutoSplitDoublePage bool `yaml:"auto_split_double_page"` - NoBlankPage bool `yaml:"no_blank_page"` - Manga bool `yaml:"manga"` - HasCover bool `yaml:"has_cover"` - AddPanelView bool `yaml:"add_panel_view"` - LimitMb int `yaml:"limit_mb"` + Profile string `yaml:"profile"` + Quality int `yaml:"quality"` + Crop bool `yaml:"crop"` + Brightness int `yaml:"brightness"` + Contrast int `yaml:"contrast"` + AutoRotate bool `yaml:"auto_rotate"` + AutoSplitDoublePage bool `yaml:"auto_split_double_page"` + NoBlankPage bool `yaml:"no_blank_page"` + Manga bool `yaml:"manga"` + 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:"-"` @@ -48,19 +49,20 @@ type Options struct { func New() *Options { return &Options{ - Profile: "", - Quality: 85, - Crop: true, - Brightness: 0, - Contrast: 0, - AutoRotate: false, - AutoSplitDoublePage: false, - NoBlankPage: false, - Manga: false, - HasCover: true, - AddPanelView: false, - LimitMb: 0, - profiles: profiles.New(), + Profile: "", + Quality: 85, + Crop: true, + Brightness: 0, + Contrast: 0, + AutoRotate: false, + AutoSplitDoublePage: false, + NoBlankPage: false, + Manga: false, + HasCover: true, + AddPanelView: false, + LimitMb: 0, + StripFirstDirectoryFromToc: false, + profiles: profiles.New(), } } @@ -72,11 +74,11 @@ Options:` func (o *Options) String() string { return fmt.Sprintf(`%s - Input : %s - Output : %s - Author : %s - Title : %s - Workers : %d%s + Input : %s + Output : %s + Author : %s + Title : %s + Workers : %d%s `, o.Header(), o.Input, @@ -126,18 +128,19 @@ func (o *Options) ShowDefault() string { } return fmt.Sprintf(` - Profile : %s - Quality : %d - Crop : %v - Brightness : %d - Contrast : %d - AutoRotate : %v - AutoSplitDoublePage: %v - NoBlankPage : %v - Manga : %v - HasCover : %v - AddPanelView : %v - LimitMb : %s`, + Profile : %s + Quality : %d + Crop : %v + Brightness : %d + Contrast : %d + AutoRotate : %v + AutoSplitDoublePage : %v + NoBlankPage : %v + Manga : %v + HasCover : %v + AddPanelView : %v + 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, ) } diff --git a/internal/epub/core.go b/internal/epub/core.go index bc17265..0a78b2f 100644 --- a/internal/epub/core.go +++ b/internal/epub/core.go @@ -32,11 +32,12 @@ type ImageOptions struct { } type EpubOptions struct { - Input string - Output string - Title string - Author string - LimitMb int + Input string + Output string + 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 { diff --git a/main.go b/main.go index 5883724..b1fcbbe 100644 --- a/main.go +++ b/main.go @@ -96,11 +96,12 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s profile := cmd.Options.GetProfile() if err := epub.NewEpub(&epub.EpubOptions{ - Input: cmd.Options.Input, - Output: cmd.Options.Output, - LimitMb: cmd.Options.LimitMb, - Title: cmd.Options.Title, - Author: cmd.Options.Author, + Input: cmd.Options.Input, + Output: cmd.Options.Output, + 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,