gokarna-theme / gokarna-hugo

A minimal opinionated theme for Hugo
https://gokarna-hugo.netlify.app
GNU General Public License v3.0
357 stars 139 forks source link

SVG Injection bug when hosting on non-canonical url #255

Closed alanmcruickshank closed 1 day ago

alanmcruickshank commented 5 days ago

Hello. First: great theme 👍 . Thanks for putting this together.

We've just started using this theme on the homepage for the open source project SQLFluff: https://sqlfluff.com

In local development (using hugo server), the feather icons render fine, and when deployed (i.e. actually at sqlfluff.com, built using hugo --gc --minify) the feather icons also render fine. However, we use netlify for development builds, which naturally deploy to a different url (for example right now you can find a deployment preview demonstrating this issue here: https://deploy-preview-8--sqlfluff.netlify.app/).

In that environment, the feather icons don't resolve. I've had a look at the console, and I can see the following errors: image

It looks like the javascript to inject the svg files is trying to resolve the paths on the production domain, but they a) don't exist there yet in this case and b) even the ones that do raise a CORS error.

What's puzzling me is that it works fine in development, where the url is localhost, even when the svg images aren't deployed in production. That's as far as I've got in my debugging, but I'd love a way to force the svg injection to use a relative path so that it doesn't care what domain it's deployed on. Is that possible?

I'm happy to raise a PR if you give me some pointers on where the path resolution happens, but my javascript fu was not good enough to work that out on my own.

jamesericdavidson commented 5 days ago

Hi Alan,

Have you looked into the CORS errors? At first blush this looks like it's caused by the disparity between domains.

Regards,

James Davidson

-------- Original Message -------- On 16/10/2024 22:54, Alan Cruickshank wrote:

Hello. First: great theme 👍 . Thanks for putting this together.

We've just started using this theme on the homepage for the open source project SQLFluff: https://sqlfluff.com

In local development (using hugo server), the feather icons render fine, and when deployed (i.e. actually at sqlfluff.com, built using hugo --gc --minify) the feather icons also render fine. However, we use netlify for development builds, which naturally deploy to a different url (for example right now you can find a deployment preview demonstrating this issue here: https://deploy-preview-8--sqlfluff.netlify.app/).

In that environment, the feather icons don't resolve. I've had a look at the console, and I can see the following errors: image.png (view on web)

It looks like the javascript to inject the svg files is trying to resolve the paths on the production domain, but they a) don't exist there yet in this case and b) even the ones that do raise a CORS error.

What's puzzling me is that it works fine in development, where the url is localhost, even when the svg images aren't deployed in production. That's as far as I've got in my debugging, but I'd love a way to force the svg injection to use a relative path so that it doesn't care what domain it's deployed on. Is that possible?

I'm happy to raise a PR if you give me some pointers on where the path resolution happens, but my javascript fu was not good enough to work that out on my own.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

alanmcruickshank commented 5 days ago

Thanks @jamesericdavidson . I agree, and I've done some digging and found the issue. I think my issue is caused by the #249, and the fix used there. By moving to absUrl, we resolve the issue of non-root hosting, but in turn break references when hosting on a different domain.

alanmcruickshank commented 5 days ago

Would you be open to switching from absUrl to relUrl there? I think that should solve both issues.

Docs links:

cc @pkierski as the author of #249

alanmcruickshank commented 5 days ago

@jamesericdavidson - for reference, if you look at the deploy preview for this repository on #249 - the social icons are broken. That's probably a fair demonstration that it's not just on the sqlfluff project that this issue is happening. I've confirmed on my project that switching to relUrl solves the issue.

pkierski commented 5 days ago

Would you be open to switching from absUrl to relUrl there? I think that should solve both issues.

Definitely. I've just tested relUrl as solution for non-root hosting and it works well.