SaraVieira / starter-book

A book starter to kickstart your writing journey 🎉

Home Page:https://saravieira.github.io/starter-book/#/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Image not downloaded for Epub?

nathansebhastian opened this issue · comments

Hello Sara,

I tried to generate an epub book with the script, but I have image download error from my console:

node generate-book/epub.js
Generating Template Files.....
Downloading Images...
[Download Error] Error while downloading ./cat.jpg { [Error: ENOENT: no such file or directory, open '/Users/nsebhastian/Desktop/starter-book/node_modules/epub-gen/tempDir/b99c020e-17bc-43e4-96f8-f958823440e9/OEBPS/cat.jpg']
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path:
   '/Users/nsebhastian/Desktop/starter-book/node_modules/epub-gen/tempDir/b99c020e-17bc-43e4-96f8-f958823440e9/OEBPS/cat.jpg' }
Making Cover...
[Success] cover image downloaded successfully!
Generating Epub Files...

It seems that the epub-gen library can't download images unless it's absolute path or HTTP?
Is there a workaround for this?

Thank you!

Hey

I actually encountered that too and that's why in the end and ended up uploading all images to a Cloudinary account :/

I do not have a workaround, sorry

Hi Sara,

No worries! I have managed to create a workaround by adding a new image renderer that replace the relative path with absolute path to the image src like this:

export const absoluteImageRenderer = ({ src, alt }) => {
  src = src.replace("./", "http://localhost:9000/")
  return (
    <figure>
      <img src={src} alt={alt} />
      <figcaption>{alt}</figcaption>
    </figure>
  );
}

Then call it only under GATSBY_SCRAPPER:

process.env.GATSBY_SCRAPPER === "1"
       ? {
           heading: headingRenderer,
           root: SmallRootRenderer,
           image: absoluteImageRenderer,
         }
       :

I'm using localhost:9000 because gatsby serve the local site there. May I create a pull request on this issue? Then you can review it afterward :)

Heyy

That is smart!!!

Please do :)