Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forced to use Absolute URLs in Jekyll

I am trying to set up a personal homepage with Jekyll using the domain provided by my University.

An issue that I have not been able to resolve is Jekyll forcing me to use absolute paths which I believe are not compatible with the webpage hosting service.

The _config.yml file determines how Jekyll generates linkings in the index.html file which is the homepage. _config.yml looks like this...

title: Homepage | Ishank Juneja 
email: [email protected]
description: >- # this means to ignore newlines until "baseurl:"
Personal homepage Beta version
baseurl: "foobar" # the subpath of your 
site, e.g. /blog
url: "http://home.iitb.ac.in/~ishankjuneja" # the base hostname & protocol for your site, e.g. 
http://example.com
twitter_username: ishankjuneja
github_username:  ishank-juneja

# Build settings
markdown: kramdown
theme: minima
plugins:
- jekyll-feed

An example of the (many) linkings it generates in the index.html file is

<link rel="stylesheet" href="/foobar/assets/main.css"> 

This link explained to me that this is, in fact, an absolute path, which didn't seem like a problem to me, but the Directory Tree on the Web hosting service looks like,

public_html
├── 404.html
├── about
│   └── index.html
├── assets
│   ├── main.css
│   └── minima-social-icons.svg
├── feed.xml
├── index.html
└── jekyll
    └── update
        └── 2018
            └── 10
                └── 04
                    └── test-post.html

The URL for my homepage http://home.iitb.ac.in/~ishankjuneja/ is associated with the folder public_html, so the path for main.css above would be incorrect. Something like href="assets/main.css" works well, but there seems to be nothing that I can type in _config.yml to get this result.

like image 248
ijuneja Avatar asked Jan 27 '23 08:01

ijuneja


2 Answers

In configuration you have to properly set up baseurl:

baseurl: "~ishankjuneja"

Then use

 {{site.baseurl}}page.url
like image 157
marcanuy Avatar answered Jan 29 '23 22:01

marcanuy


In your example , putting /foobar (the baseurl in _config.yml) is not a good idea.

Using absolute URl is not a good idea either as you have said.

The solution is to use relative_url Liquid Filter as

<link rel="stylesheet" href={{"/assets/main.css" | relative_url }} > 

similar solution as @Aleksandr Kiselev suggested.

like image 41
kuolai shu Avatar answered Jan 29 '23 21:01

kuolai shu