ghostwriter icon indicating copy to clipboard operation
ghostwriter copied to clipboard

Missing / in resource url when previewing on Netlify

Open cderv opened this issue 4 years ago • 2 comments

When I deploy a branch preview on Netlify, the site using this theme does not look right because the CSS and JS resources from the theme are not found.

I believe this is because {{.Site.BaseURL}} is used, and it does not add missing trailing slash. I have one in my baseURL config but Netlify sets none when changing the base URL.

https://github.com/jbub/ghostwriter/blob/2dd435c21fcdcb1af253814b1198dc075553542d/layouts/partials/header.html#L14-L15

However, it seems that loading resource this way is not advice. See https://github.com/gohugoio/hugo/issues/3262#issuecomment-290991303 where the maintainer of hugo advice the following

But manually creating URLs using {{ .Site.BaseURL }} is fragile, esp. for themes, and not recommended. Use absURL and friends, and you should not have to worry about slashes.

Using relURL or absURL would be better I believe.

  • https://gohugo.io/functions/relurl/
  • https://gohugo.io/functions/absurl/

This fix the issue I encounter if I tweak the theme. But there are a lot of occurrences in the theme of this. I think this should be fixed as the theme level.

Does this cause any issue with anyone in the past ?

cderv avatar Jun 29 '21 12:06 cderv

Here is the diff of my changes so that it works ok https://github.com/jbub/ghostwriter/compare/master...cderv:fix-url

cderv avatar Jun 29 '21 12:06 cderv

Thanks for this, @cderv. I had the exact same issue and pointing to your branch does fix the issue. However, it does break the workflow for local builds. I now need to pass the base url manually: hugo -b file:///path/to/my/hugo/project. hugo serve still seems to work fine

ludaavics avatar Jul 04 '21 01:07 ludaavics