From 4a437605350cae11c9fd0131952ab4d3ba558f45 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Sat, 22 Apr 2023 10:26:11 +0200 Subject: [PATCH] add at least one child in the toc --- internal/epub/image_filters.go | 2 +- internal/epub/toc.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/epub/image_filters.go b/internal/epub/image_filters.go index 0eaa039..2714565 100644 --- a/internal/epub/image_filters.go +++ b/internal/epub/image_filters.go @@ -20,8 +20,8 @@ func NewGift(options *ImageOptions) *gift.GIFT { } g.Add( filters.Resize(options.ViewWidth, options.ViewHeight, gift.LanczosResampling), - filters.Pixel(), filters.Position(options.ViewWidth, options.ViewHeight, filters.PositionCenter), + filters.Pixel(), ) return g } diff --git a/internal/epub/toc.go b/internal/epub/toc.go index d354457..7c625b3 100644 --- a/internal/epub/toc.go +++ b/internal/epub/toc.go @@ -44,9 +44,14 @@ func (e *ePub) getToc(title string, images []*Image) string { if len(ol.ChildElements()) == 1 && e.StripFirstDirectoryFromToc { ol = ol.ChildElements()[0] } - if len(ol.ChildElements()) > 0 { - nav.AddChild(ol) - } + + beginning := etree.NewElement("li") + beginningLink := beginning.CreateElement("a") + beginningLink.CreateAttr("href", images[0].TextPath()) + beginningLink.CreateText("Start of the book") + ol.InsertChildAt(0, beginning) + + nav.AddChild(ol) doc.Indent(2) r, _ := doc.WriteToString()