zwbetz-gh / cupper-hugo-theme

An accessibility-friendly Hugo theme, ported from the original Cupper project.
https://cupper-hugo-theme.netlify.app/
MIT License
301 stars 190 forks source link

Fix favicon links when using a / in baseURL #53

Closed JulesFouchy closed 3 years ago

JulesFouchy commented 3 years ago

I noticed that when baseURL contains a / like

// config.yaml
baseURL: https://example/oopsie

(which typically happens when you host your site on GitHub Pages) the favicon links don't work.

I fixed it by prefixing the links with baseURL.

zwbetz-gh commented 3 years ago

Thanks for this.

I prefer not to prefix with .Site.BaseURL, because some users have the trailing slash, and some do not.

Instead, does absURL work for you?

<link rel="apple-touch-icon" sizes="180x180" href="{{ absURL | "/apple-touch-icon.png" }}">
JulesFouchy commented 3 years ago

Unfortunately no

<link rel="apple-touch-icon" sizes="180x180" href="{{ absURL  "/apple-touch-icon.png" }}">

evaluates to

http://localhost:1313/apple-touch-icon.png

and not

http://localhost:1313/oopsie/apple-touch-icon.png

But I tested with and without trailing slash, and even though (in both cases)

<link rel="apple-touch-icon" sizes="180x180" href={{ print .Site.BaseURL "/apple-touch-icon.png" }}> 

evaluates to

http://localhost:1313/oopsie//apple-touch-icon.png

the link still works (on my version of Firefox, Chrome and Edge at least).

zwbetz-gh commented 3 years ago

Okay, looks like I learned something new today.

a) The first example I have was wrong, I switched up the param order by mistake. Instead, it should be:

<link rel="apple-touch-icon" sizes="180x180" href="{{ "apple-touch-icon.png" | absURL }}">

Which outputs:

<link rel="apple-touch-icon" sizes="180x180" href="http://localhost:1313/oopsie/apple-touch-icon.png">

b) Turns out that when passing a string to absURL that has a leading slash, it doesn't prepend the full BaseURL. But, once the leading slash is removed, it works as expected.

JulesFouchy commented 3 years ago

Yes indeed ! Thanks ! I'm updating the PR.

zwbetz-gh commented 3 years ago

Looks good.