Closed JulesFouchy closed 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" }}">
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).
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.
Yes indeed ! Thanks ! I'm updating the PR.
Looks good.
I noticed that when baseURL contains a / like
(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.