jbub / ghostwriter

A port of ghostwriter theme to Hugo.
MIT License
177 stars 154 forks source link

Missing / in resource url when previewing on Netlify #102

Open cderv opened 3 years ago

cderv commented 3 years ago

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.

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 commented 3 years ago

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

ludaavics commented 3 years ago

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