cyrilis / epub-gen

Generate EPUB books from HTML with simple API in Node.js.
428 stars 135 forks source link

a couple of bugs when using epub-gen #93

Open mcthulhu opened 3 years ago

mcthulhu commented 3 years ago

The table of contents' first entry is "Table of Contents," instead of the first chapter, which is the second entry. I see that there were previous issues related to this that were supposedly fixed.

Verbose mode confirms that the cover image has been successfully downloaded, and it's part of the epub, but no cover is displayed. The first page shown is the table of contents. This happens in two different epub readers. There is no indication in the verbose output that there is a problem:

Generating Template Files.....
Downloading Images...
Making Cover...
(node:15116) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
[Success] cover image downloaded successfully!
Generating Epub Files...

Before I try to modify the epub structure after the fact, is there anything I can do to fix these problems when generating the books? The epubs seem to work OK except for the missing cover and the TOC.

Firsh commented 2 years ago

You can fix the cover: https://github.com/cyrilis/epub-gen/issues/64#issuecomment-1191863881

I believe the TOC being in the TOC is not so bad, in some retail epubs I see the same.* However there is a distinction between the actual TOC that is on a page, and the virtual one that the readers open for you and render with their own design. In the latter I think it's helpful to include the TOC link and some retail ones do that. In the other one, not so much and I never seen that in production.

How do retail epubs put the contents link in the calibre reader sidebar or the device-rendered toc, but not redundantly into the content page? I've seen that the toc page that the device uses is not registered to be in the spine. In calibre's editor, file browser panel, the tox.xhtml (EPUB 3) is not among the Text, is under Misc. There is a different one, a copy, without the contents link that is simply regular content which appears to be a list of links, and is styled a bit differently and more manually, as anything goes there. Epub-gen has 1 toc for all purposes, you can reach it by paging in the book and it's also used as the device-rendered one.

I'll take a look at what template can be modified to leave it out from there. Removing the table of contents entry from the table of contents:

        <li class="table-of-content">
            <a href="toc.xhtml">- <%= tocTitle %> -</a>
        </li>

This needs to go from your local copy of toc.xhtml.ejs that you source using the top-level option:

        customHtmlTocTemplatePath: path.join(__dirname, 'templates', 'toc.xhtml.ejs'),

If you want to retain it but remove those pesky dashes from its side, this is also the way.

In the end, I prefer to have no TOC link in the TOC, since readers have their own UI way of opening it. Having it in the content bears no real benefit (I'd even go as far as omitting it entirely or placing it at the end) besides going through the names of chapters before/after reading a book. But realistically, say, if you are on page 398 of a book and you want to look at the contents, the first thing you do is to bring up the device/readerapp's rendering of the TOC and not navigate to page 2...