Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image not downloaded for Epub? #8

Open
codewithnathan97 opened this issue Dec 27, 2020 · 3 comments · May be fixed by #10
Open

Image not downloaded for Epub? #8

codewithnathan97 opened this issue Dec 27, 2020 · 3 comments · May be fixed by #10

Comments

@codewithnathan97
Copy link

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!

@SaraVieira
Copy link
Owner

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

@codewithnathan97
Copy link
Author

codewithnathan97 commented Dec 31, 2020

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 :)

@SaraVieira
Copy link
Owner

Heyy

That is smart!!!

Please do :)

@codewithnathan97 codewithnathan97 linked a pull request Dec 31, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants