I facing difficult understanding relative_url and baseurl.
I have deployed a site on gitlab pages and in I have used relative_url in all the links but I didn’t use baseurl in the _config.yml file and it didn’t work.
But when I deployed the same on netlify it works.
If I use baseurl, for example: baseurl: /blog/, and along with that if I use relative_url in the links then it append the baseurl to the links.
The relative_url filter adds in whatever you’re using as baseurl in your _config.yml. There’s no point to us it if you’re already hardcoding that value into your links.
absolute_url filter works similar but takes site.url + site.baseurl and prepends URLs with them.
@yashumittalbaseurl, relative_url are two different entities.
When you set baseurl: "/blog", Jekyll considers /blog/ as the root of your website. i.e. Instead of having your site served at http://localhost:4000/, you’ll have it served at http://localhost:4000/blog/ instead.
Jekyll expects you to code links in your templates in the same fashion. This is why you would see some templates containing variations of the following:
There is a problem with the above usage though. Users can configure baseurl: to be a string with containing variable numbers of slashes (e.g., '/' or '/blog/' or 'blog/' or '/blog//'). Jekyll wouldn’t care about the values set and would simply result in improper links in their HTML.
That’s when Jekyll introduced Liquid Filters: relative_url and absolute_url
relative_url ensures proper links by:
ensuring the url to have a single leading slash always
ensuring there are no unnecessary slashes.
The template just has to have a single construct {{ 'css/style.css' | relative_url }} and the links would be proper (/blog/css/style.css) for all the scenarios I mentioned above ('/blog/' or 'blog/' or '/blog//')
I ran across this thread trying to solve a similar problem. I don’t have a github site yet, just doing everything locally, and my baseurl = “/mish”, so my URLs are http://localhost:4000/mish/, but I do not want a baseurl, or rather, I want the baseurl to be “/”, but then the pages can’t find any images, css, etc, which I do not understand because the server is actually running in the “/mish” directory, so the actual baseurl IS “/”.
Is the baseurl allowed to be just “/” or even “” ?
In v4.0.0 post_url tag now incorporates the relative_url filter within itself and therefore automatically prepends site’s baseurl to the post’s url value. If I have to remove all {{ site.baseurl }} based on this new upgrade…
What should I do in main.scss file with $baseurl variable? Remove it?
(in Jekyll v3.x was $baseurl: "{{ site.baseurl }}";)