mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
add option to strip first directory from toc
This commit is contained in:
parent
a24bf0cfc8
commit
0e9ae95df0
@ -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.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.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.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.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")
|
||||||
|
@ -20,18 +20,19 @@ type Options struct {
|
|||||||
Dry bool `yaml:"-"`
|
Dry bool `yaml:"-"`
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
Profile string `yaml:"profile"`
|
Profile string `yaml:"profile"`
|
||||||
Quality int `yaml:"quality"`
|
Quality int `yaml:"quality"`
|
||||||
Crop bool `yaml:"crop"`
|
Crop bool `yaml:"crop"`
|
||||||
Brightness int `yaml:"brightness"`
|
Brightness int `yaml:"brightness"`
|
||||||
Contrast int `yaml:"contrast"`
|
Contrast int `yaml:"contrast"`
|
||||||
AutoRotate bool `yaml:"auto_rotate"`
|
AutoRotate bool `yaml:"auto_rotate"`
|
||||||
AutoSplitDoublePage bool `yaml:"auto_split_double_page"`
|
AutoSplitDoublePage bool `yaml:"auto_split_double_page"`
|
||||||
NoBlankPage bool `yaml:"no_blank_page"`
|
NoBlankPage bool `yaml:"no_blank_page"`
|
||||||
Manga bool `yaml:"manga"`
|
Manga bool `yaml:"manga"`
|
||||||
HasCover bool `yaml:"has_cover"`
|
HasCover bool `yaml:"has_cover"`
|
||||||
AddPanelView bool `yaml:"add_panel_view"`
|
AddPanelView bool `yaml:"add_panel_view"`
|
||||||
LimitMb int `yaml:"limit_mb"`
|
LimitMb int `yaml:"limit_mb"`
|
||||||
|
StripFirstDirectoryFromToc bool `yaml:"strip_first_directory_from_toc"`
|
||||||
|
|
||||||
// Default Config
|
// Default Config
|
||||||
Show bool `yaml:"-"`
|
Show bool `yaml:"-"`
|
||||||
@ -48,19 +49,20 @@ type Options struct {
|
|||||||
|
|
||||||
func New() *Options {
|
func New() *Options {
|
||||||
return &Options{
|
return &Options{
|
||||||
Profile: "",
|
Profile: "",
|
||||||
Quality: 85,
|
Quality: 85,
|
||||||
Crop: true,
|
Crop: true,
|
||||||
Brightness: 0,
|
Brightness: 0,
|
||||||
Contrast: 0,
|
Contrast: 0,
|
||||||
AutoRotate: false,
|
AutoRotate: false,
|
||||||
AutoSplitDoublePage: false,
|
AutoSplitDoublePage: false,
|
||||||
NoBlankPage: false,
|
NoBlankPage: false,
|
||||||
Manga: false,
|
Manga: false,
|
||||||
HasCover: true,
|
HasCover: true,
|
||||||
AddPanelView: false,
|
AddPanelView: false,
|
||||||
LimitMb: 0,
|
LimitMb: 0,
|
||||||
profiles: profiles.New(),
|
StripFirstDirectoryFromToc: false,
|
||||||
|
profiles: profiles.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,11 +74,11 @@ Options:`
|
|||||||
|
|
||||||
func (o *Options) String() string {
|
func (o *Options) String() string {
|
||||||
return fmt.Sprintf(`%s
|
return fmt.Sprintf(`%s
|
||||||
Input : %s
|
Input : %s
|
||||||
Output : %s
|
Output : %s
|
||||||
Author : %s
|
Author : %s
|
||||||
Title : %s
|
Title : %s
|
||||||
Workers : %d%s
|
Workers : %d%s
|
||||||
`,
|
`,
|
||||||
o.Header(),
|
o.Header(),
|
||||||
o.Input,
|
o.Input,
|
||||||
@ -126,18 +128,19 @@ func (o *Options) ShowDefault() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
Profile : %s
|
Profile : %s
|
||||||
Quality : %d
|
Quality : %d
|
||||||
Crop : %v
|
Crop : %v
|
||||||
Brightness : %d
|
Brightness : %d
|
||||||
Contrast : %d
|
Contrast : %d
|
||||||
AutoRotate : %v
|
AutoRotate : %v
|
||||||
AutoSplitDoublePage: %v
|
AutoSplitDoublePage : %v
|
||||||
NoBlankPage : %v
|
NoBlankPage : %v
|
||||||
Manga : %v
|
Manga : %v
|
||||||
HasCover : %v
|
HasCover : %v
|
||||||
AddPanelView : %v
|
AddPanelView : %v
|
||||||
LimitMb : %s`,
|
LimitMb : %s
|
||||||
|
StripFirstDirectoryFromToc: %v`,
|
||||||
profileDesc,
|
profileDesc,
|
||||||
o.Quality,
|
o.Quality,
|
||||||
o.Crop,
|
o.Crop,
|
||||||
@ -150,6 +153,7 @@ func (o *Options) ShowDefault() string {
|
|||||||
o.HasCover,
|
o.HasCover,
|
||||||
o.AddPanelView,
|
o.AddPanelView,
|
||||||
limitmb,
|
limitmb,
|
||||||
|
o.StripFirstDirectoryFromToc,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,11 +32,12 @@ type ImageOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type EpubOptions struct {
|
type EpubOptions struct {
|
||||||
Input string
|
Input string
|
||||||
Output string
|
Output string
|
||||||
Title string
|
Title string
|
||||||
Author string
|
Author string
|
||||||
LimitMb int
|
LimitMb int
|
||||||
|
StripFirstDirectoryFromToc bool
|
||||||
|
|
||||||
*ImageOptions
|
*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)
|
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 []byte{}, nil
|
||||||
}
|
}
|
||||||
return xml.MarshalIndent(paths["."].Children.Tags, " ", " ")
|
|
||||||
|
return xml.MarshalIndent(children.Tags, " ", " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ePub) Write() error {
|
func (e *ePub) Write() error {
|
||||||
|
11
main.go
11
main.go
@ -96,11 +96,12 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
|
|||||||
|
|
||||||
profile := cmd.Options.GetProfile()
|
profile := cmd.Options.GetProfile()
|
||||||
if err := epub.NewEpub(&epub.EpubOptions{
|
if err := epub.NewEpub(&epub.EpubOptions{
|
||||||
Input: cmd.Options.Input,
|
Input: cmd.Options.Input,
|
||||||
Output: cmd.Options.Output,
|
Output: cmd.Options.Output,
|
||||||
LimitMb: cmd.Options.LimitMb,
|
LimitMb: cmd.Options.LimitMb,
|
||||||
Title: cmd.Options.Title,
|
Title: cmd.Options.Title,
|
||||||
Author: cmd.Options.Author,
|
Author: cmd.Options.Author,
|
||||||
|
StripFirstDirectoryFromToc: cmd.Options.StripFirstDirectoryFromToc,
|
||||||
ImageOptions: &epub.ImageOptions{
|
ImageOptions: &epub.ImageOptions{
|
||||||
ViewWidth: profile.Width,
|
ViewWidth: profile.Width,
|
||||||
ViewHeight: profile.Height,
|
ViewHeight: profile.Height,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user