Hello!
Controlling links in Jekyll honestly is really a mess and if you want to be able to host your site in a sub-folder you need to prepend {{ site.baseurl }}
for each link.
So I’d like to know if there is a plugin or something that automatically prepends site.baseurl
to each link.
Thanks!
It sounds like you are spending a lot of time creating variables to build the url, but in general, you do not have to do that.
To get what you want, you should pipe in a filter for the relative_url
or absolute_url
.
Relative url
<a href="{{- '/mypages/support.html' | relative_url -}}">Visit our support page</a>
The final result for the url could look something like this:
/mywebsite/mypages/support.html
Absolute url
Alternatively, you can use the absolute_url filter, like this:
<a href="{{- '/mypages/support.html' | absolute_url -}}">Visit our support page</a>
The final result for the url could look something like this:
https://www.myurl.com/mywebsite/mypages/support.html
Further reading
You will of course need to do the one-time configuration of setting up your _conifg.yml
file with the base_url
and url
. There’s an excellent definition of all this on the the official Jekyll documentation site:
Well that’s already better and that will definitely help me, so thanks!
But we still need to put that | relative_url
which can be a pain when having a lot of assets
Note : that doesn’t work with jekyll-multiple-languages-plugin
Maybe I could make a plugin that automatically detects if there is a /
at the beginning of the URL and prepend the relative or absolute URL if so