jrit / web-resource-inliner

Inlines img, script and link tags into the same file
MIT License
69 stars 30 forks source link

Support embedding local paths using file:// #46

Open offbynull opened 5 years ago

offbynull commented 5 years ago

If file:// is encountered, web-resource-inliner should correctly embed the file referenced. Currently it just appends the entire link to the relativeTo path, which causes inline-ing to fail. For example, if relativeTo is set to /a/b/c, the link file:///x/y/z.js gets translated to /a/b/c/file:/x/y/z.js.

jrit commented 5 years ago

Would accept a PR that does this

offbynull commented 5 years ago

Was there not a PR already submitted for this?

On Tue, Jul 9, 2019, 3:44 PM Jarrett Widman, notifications@github.com wrote:

Would accept a PR that does this

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jrit/web-resource-inliner/issues/46?email_source=notifications&email_token=ABQPQIVK6VG4STSDJCNB3QLP6TTAXA5CNFSM4H4N35N2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZRKE3I#issuecomment-509780589, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQPQISVVDS2XOXEEI24T2TP6TTAXANCNFSM4H4N35NQ .

GaelGirodon commented 5 years ago

Hello, I have an issue related to this one working with absolute local paths.

Currently, the file URL scheme is not supported (file://) as reported by @offbynull, so, lines like this one aren't processed as they should be:

<link rel="stylesheet" href="file:///absolute/path/to/style.css">

To get rid of this issue, I pre-process the HTML file and remove file://.

It works on Windows (I get a path like C:/absolute/path/to/style.css that is processed correctly) but not on Linux because of this line of code. And that's not really a bug, because a path beginning with / normally refers to the website root (so, it is normal to prefix it with the relativeTo path value during inlining) but I don't find a way to provide a local path relative to the filesystem root (and not the website root).

I don't see how to solve this problem except by implementing the file URL scheme (to be able to provide FS absolute path) but I don't know enough about it to propose a good implementation right now.

What is your opinion on this subject?

PS : apart from this issue, @jrit, thanks for this very good tool, you really made my job easier when I built my last project!