lesjoursfr / html-to-epub

Generate EPUB books from HTML with simple API in Node.js.
MIT License
39 stars 16 forks source link

Automatically generate a cover page when a cover image path is specified #114

Closed MrHands closed 10 months ago

MrHands commented 10 months ago

I'm targeting a very old ebook reader for my book, a Kobo Glo HD from 2015, and I noticed that my device wasn't picking up on the cover image I added to my book. After investigating the docs for the ePub format, I found some things that could be improved for your library. My changes automatically add a cover page to the output epub based on the new template cover.xhtml.ejs that can be overridden with the new customHtmlCoverTemplatePath option. The cover page uses an SVG with the exact dimensions of the supplied image that looks perfect, even on my ancient device.

To do all this, I've introduced a templatePath member for EpubContent items and cleaned up page generation by adding a content.xhtml.ejs template. The new cover page generation is inserted before other pages and swaps out the templatePath parameter. I've also had to move image loading before template generation to ensure the image dimensions are available for the cover page template.

Thank you for a wonderful library; you've already saved me a heap of time!

e-adrien commented 10 months ago

Hi.

Thanks for this PR. CI is failing but it's related to this issue https://github.com/TypeStrong/ts-node/issues/2076

There is a lot of changes in the src/index.ts file but I will try to review it before the end of the month.

MrHands commented 10 months ago

Thanks for getting back to me! I'm currently using the modified version of your code for my project, so there's no rush in getting these changes merged upstream. I'm happy to address any concerns you might have.

e-adrien commented 10 months ago

All good to me, thank you again for this PR.

MrHands commented 10 months ago

No problem at all; I'm happy to have contributed to an awesome project that has already saved me a lot of time! 😊