jgazeau / website2pdf

Node library to print PDFs from a website following sitemap protocol
MIT License
26 stars 6 forks source link

[bug]: write file fails when "|" (pipe) present in filename #58

Closed whyboris closed 2 years ago

whyboris commented 2 years ago

Steps that lead to the issue

Version 0.0.7 worked:

Introduction_to_Utilitarianism_My_blog.pdf

Version 0.0.8 does not

Introduction to Utilitarianism | My blog.pdf

The change with #47 results in the situation where Node tries to create a file with a | character and fails:

ERROR ENOENT: no such file or directory, open 'C:\Code\utilitarianism\pdf\w2pdf_output\en\introduction-to-utilitarianism\Introduction to Utilitarianism | My blog.pdf'

Expected behavior

Remove the error-causing character | 🤔

Reproducer

Make sure the title of the webpage includes the | character :trollface:

Solution?

Maybe include a filter to remove problematic characters during the operation of the toFilename helper function:

https://github.com/jgazeau/website2pdf/blob/main/src/utils/helpers.ts#L35

whyboris commented 2 years ago

🙇 by the way, @jgazeau 🙇 THANK YOU SO MUCH for this useful utility you created and shared with the world ❤️

I am building a Hugo website and now I can generate beautiful PDFs with your tool:

https://github.com/whyboris/utilitarianism.net/pull/41

Thank you 😊

ps - the above bug I reported doesn't matter to me - I can fix it locally in 1 second by removing the | from page titles 👌 I'm reporting it just FYI -- feel free to close 👌

jgazeau commented 2 years ago

Hi @whyboris , Glad you use my library and like it 😊 Actually this is a regression from this issue. I kind of change it too hardly 😄 . What I will do is actually add an option to safely generate files by replacing all special char in the filename (as it was in the v0.0.7), and by default the filename will be the one from the title tag.

I'll try to do it this week and release right after 😉

jgazeau commented 2 years ago

Hi @whyboris , release 0.0.9 is out now with the safeTitle option :)

whyboris commented 1 year ago

@jgazeau - 🙇 thank you again for this excellent tool ❤️ Thanks to you we now have PDFs of all the pages: https://www.utilitarianism.net/ https://github.com/whyboris/utilitarianism.net 🚀 (see the thank you at the bottom of our repository 😊 )