mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 07:42:37 +02:00
improve part html
This commit is contained in:
parent
6444eb65a3
commit
fd80342a19
@ -49,10 +49,8 @@ type EPub struct {
|
||||
}
|
||||
|
||||
type EpubPart struct {
|
||||
Idx int
|
||||
Cover *Image
|
||||
Images []*Image
|
||||
Suffix string
|
||||
}
|
||||
|
||||
func NewEpub(path string) *EPub {
|
||||
@ -221,7 +219,7 @@ func (e *EPub) LoadDir(dirname string) *EPub {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *EPub) GetParts() <-chan *EpubPart {
|
||||
func (e *EPub) GetParts() []*EpubPart {
|
||||
images := make([]*Image, e.ImagesCount)
|
||||
totalSize := 0
|
||||
bar := progressbar.Default(int64(e.ImagesCount), "Processing")
|
||||
@ -232,20 +230,16 @@ func (e *EPub) GetParts() <-chan *EpubPart {
|
||||
}
|
||||
bar.Close()
|
||||
|
||||
epubPart := make(chan *EpubPart)
|
||||
go func() {
|
||||
defer close(epubPart)
|
||||
epubPart := make([]*EpubPart, 0)
|
||||
|
||||
cover := images[0]
|
||||
images = images[1:]
|
||||
fmt.Println("Limit: ", e.LimitMb, e.LimitMb == 0)
|
||||
if e.LimitMb == 0 {
|
||||
epubPart <- &EpubPart{
|
||||
Idx: 1,
|
||||
epubPart = append(epubPart, &EpubPart{
|
||||
Cover: cover,
|
||||
Images: images,
|
||||
Suffix: "",
|
||||
}
|
||||
return
|
||||
})
|
||||
return epubPart
|
||||
}
|
||||
|
||||
maxSize := e.LimitMb * 1024 * 1024
|
||||
@ -255,12 +249,10 @@ func (e *EPub) GetParts() <-chan *EpubPart {
|
||||
|
||||
for _, img := range images {
|
||||
if len(currentImages) > 0 && currentSize+len(img.Data) > maxSize {
|
||||
epubPart <- &EpubPart{
|
||||
Idx: part,
|
||||
epubPart = append(epubPart, &EpubPart{
|
||||
Cover: cover,
|
||||
Images: currentImages,
|
||||
Suffix: fmt.Sprintf(" PART_%03d", part),
|
||||
}
|
||||
})
|
||||
part += 1
|
||||
currentSize = 512*1024 + len(cover.Data)
|
||||
currentImages = make([]*Image, 0)
|
||||
@ -269,14 +261,11 @@ func (e *EPub) GetParts() <-chan *EpubPart {
|
||||
currentImages = append(currentImages, img)
|
||||
}
|
||||
if len(currentImages) > 0 {
|
||||
epubPart <- &EpubPart{
|
||||
Idx: part,
|
||||
epubPart = append(epubPart, &EpubPart{
|
||||
Cover: cover,
|
||||
Images: currentImages,
|
||||
Suffix: fmt.Sprintf(" PART_%03d", part),
|
||||
})
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return epubPart
|
||||
}
|
||||
@ -291,10 +280,17 @@ func (e *EPub) Write() error {
|
||||
Content any
|
||||
}
|
||||
|
||||
for part := range e.GetParts() {
|
||||
fmt.Printf("Writing part %d...\n", part.Idx)
|
||||
epubParts := e.GetParts()
|
||||
totalParts := len(epubParts)
|
||||
|
||||
for i, part := range epubParts {
|
||||
fmt.Printf("Writing part %d...\n", i+1)
|
||||
ext := filepath.Ext(e.Path)
|
||||
path := fmt.Sprintf("%s%s%s", e.Path[0:len(e.Path)-len(ext)], part.Suffix, ext)
|
||||
suffix := ""
|
||||
if totalParts > 1 {
|
||||
suffix = fmt.Sprintf(" PART_%02d", i+1)
|
||||
}
|
||||
path := fmt.Sprintf("%s%s%s", e.Path[0:len(e.Path)-len(ext)], suffix, ext)
|
||||
w, err := os.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -307,7 +303,11 @@ func (e *EPub) Write() error {
|
||||
{"OEBPS/toc.ncx", e.Render(TEMPLATE_TOC, map[string]any{"Info": e, "Images": part.Images})},
|
||||
{"OEBPS/nav.xhtml", e.Render(TEMPLATE_NAV, map[string]any{"Info": e, "Images": part.Images})},
|
||||
{"OEBPS/Text/style.css", TEMPLATE_STYLE},
|
||||
{"OEBPS/Text/part.xhtml", e.Render(TEMPLATE_PART, map[string]any{"Info": e, "Part": part})},
|
||||
{"OEBPS/Text/part.xhtml", e.Render(TEMPLATE_PART, map[string]any{
|
||||
"Info": e,
|
||||
"Part": i + 1,
|
||||
"Total": totalParts,
|
||||
})},
|
||||
{"OEBPS/Text/cover.xhtml", e.Render(TEMPLATE_TEXT, map[string]any{
|
||||
"Id": "cover",
|
||||
"Width": part.Cover.Width,
|
||||
|
@ -2,13 +2,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
||||
<head>
|
||||
<title>Part {{ .Part.Idx }}</title>
|
||||
<title>Part {{ .Part }}</title>
|
||||
<link href="style.css" type="text/css" rel="stylesheet"/>
|
||||
<meta name="viewport" content="width={{ .Info.ViewWidth }}, height={{ .Info.ViewHeight }}"/>
|
||||
</head>
|
||||
<body style="">
|
||||
<h1 style="text-align:center;top:50%;">
|
||||
Part {{ .Part.Idx }}
|
||||
<h1 style="text-align:center;top:0%;padding-top:50%;font-size:4em">
|
||||
<p>
|
||||
{{ .Info.Title }}
|
||||
</p>
|
||||
<p>
|
||||
Part {{ .Part }} / {{ .Total }}
|
||||
</p>
|
||||
</h1>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user