mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 16:22:37 +02:00
add customization for body color
This commit is contained in:
parent
bcad0389fa
commit
94983b0c61
@ -14,6 +14,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -116,6 +117,8 @@ func (c *Converter) InitParse() {
|
|||||||
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.AddBoolParam(&c.Options.StripFirstDirectoryFromToc, "strip", c.Options.StripFirstDirectoryFromToc, "Strip first directory from the TOC if only 1")
|
||||||
c.AddIntParam(&c.Options.SortPathMode, "sort", c.Options.SortPathMode, "Sort path mode\n0 = alpha for path and file\n1 = alphanum for path and alpha for file\n2 = alphanum for path and file")
|
c.AddIntParam(&c.Options.SortPathMode, "sort", c.Options.SortPathMode, "Sort path mode\n0 = alpha for path and file\n1 = alphanum for path and alpha for file\n2 = alphanum for path and file")
|
||||||
|
c.AddStringParam(&c.Options.ForegroundColor, "foreground-color", c.Options.ForegroundColor, "Foreground color in hexa format RGB. Black=000, White=FFF")
|
||||||
|
c.AddStringParam(&c.Options.BackgroundColor, "background-color", c.Options.BackgroundColor, "Background color in hexa format RGB. Black=000, White=FFF, Light Gray=DDD, Dark Gray=777")
|
||||||
|
|
||||||
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")
|
||||||
@ -293,6 +296,16 @@ func (c *Converter) Validate() error {
|
|||||||
return errors.New("sort should be 0, 1 or 2")
|
return errors.New("sort should be 0, 1 or 2")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Color
|
||||||
|
colorRegex := regexp.MustCompile("^[0-9A-F]{3}$")
|
||||||
|
if !colorRegex.MatchString(c.Options.ForegroundColor) {
|
||||||
|
return errors.New("foreground color must have color format in hexa: [0-9A-F]{3}")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !colorRegex.MatchString(c.Options.BackgroundColor) {
|
||||||
|
return errors.New("background color must have color format in hexa: [0-9A-F]{3}")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ type Options struct {
|
|||||||
LimitMb int `yaml:"limit_mb"`
|
LimitMb int `yaml:"limit_mb"`
|
||||||
StripFirstDirectoryFromToc bool `yaml:"strip_first_directory_from_toc"`
|
StripFirstDirectoryFromToc bool `yaml:"strip_first_directory_from_toc"`
|
||||||
SortPathMode int `yaml:"sort_path_mode"`
|
SortPathMode int `yaml:"sort_path_mode"`
|
||||||
|
ForegroundColor string `yaml:"foreground_color"`
|
||||||
|
BackgroundColor string `yaml:"background_color"`
|
||||||
|
|
||||||
// Default Config
|
// Default Config
|
||||||
Show bool `yaml:"-"`
|
Show bool `yaml:"-"`
|
||||||
@ -77,6 +79,8 @@ func New() *Options {
|
|||||||
LimitMb: 0,
|
LimitMb: 0,
|
||||||
StripFirstDirectoryFromToc: false,
|
StripFirstDirectoryFromToc: false,
|
||||||
SortPathMode: 1,
|
SortPathMode: 1,
|
||||||
|
ForegroundColor: "000",
|
||||||
|
BackgroundColor: "FFF",
|
||||||
profiles: profiles.New(),
|
profiles: profiles.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,6 +186,8 @@ func (o *Options) ShowConfig() string {
|
|||||||
{"LimitMb", limitmb},
|
{"LimitMb", limitmb},
|
||||||
{"StripFirstDirectoryFromToc", o.StripFirstDirectoryFromToc},
|
{"StripFirstDirectoryFromToc", o.StripFirstDirectoryFromToc},
|
||||||
{"SortPathMode", sortpathmode},
|
{"SortPathMode", sortpathmode},
|
||||||
|
{"Foreground Color", fmt.Sprintf("#%s", o.ForegroundColor)},
|
||||||
|
{"Background Color", fmt.Sprintf("#%s", o.BackgroundColor)},
|
||||||
} {
|
} {
|
||||||
b.WriteString(fmt.Sprintf("\n %-26s: %v", v.K, v.V))
|
b.WriteString(fmt.Sprintf("\n %-26s: %v", v.K, v.V))
|
||||||
}
|
}
|
||||||
|
@ -273,8 +273,7 @@ func (e *ePub) Write() error {
|
|||||||
})},
|
})},
|
||||||
{"OEBPS/toc.xhtml", epubtemplates.Toc(title, e.StripFirstDirectoryFromToc, part.Images)},
|
{"OEBPS/toc.xhtml", epubtemplates.Toc(title, 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{
|
||||||
"PageWidth": e.Image.View.Width,
|
"View": e.Image.View,
|
||||||
"PageHeight": e.Image.View.Height,
|
|
||||||
})},
|
})},
|
||||||
{"OEBPS/Text/space_title.xhtml", e.render(epubtemplates.Blank, map[string]any{
|
{"OEBPS/Text/space_title.xhtml", e.render(epubtemplates.Blank, map[string]any{
|
||||||
"Title": "Blank Page Title",
|
"Title": "Blank Page Title",
|
||||||
|
@ -10,8 +10,13 @@ type Crop struct {
|
|||||||
Left, Up, Right, Bottom int
|
Left, Up, Right, Bottom int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Color struct {
|
||||||
|
Foreground, Background string
|
||||||
|
}
|
||||||
|
|
||||||
type View struct {
|
type View struct {
|
||||||
Width, Height int
|
Width, Height int
|
||||||
|
Color Color
|
||||||
}
|
}
|
||||||
|
|
||||||
type Image struct {
|
type Image struct {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
body {
|
body {
|
||||||
color: #000;
|
color: #{{ .View.Color.Foreground }};
|
||||||
background: #FFF;
|
background: #{{ .View.Color.Background }};
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
width: {{ .PageWidth }}px;
|
width: {{ .View.Width }}px;
|
||||||
height: {{ .PageHeight }}px;
|
height: {{ .View.Height }}px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
main.go
4
main.go
@ -132,6 +132,10 @@ $ go install github.com/celogeek/go-comic-converter/v%d@%s
|
|||||||
View: &epuboptions.View{
|
View: &epuboptions.View{
|
||||||
Width: perfectWidth,
|
Width: perfectWidth,
|
||||||
Height: perfectHeight,
|
Height: perfectHeight,
|
||||||
|
Color: epuboptions.Color{
|
||||||
|
Foreground: cmd.Options.ForegroundColor,
|
||||||
|
Background: cmd.Options.BackgroundColor,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}).Write(); err != nil {
|
}).Write(); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user