Galaxy
Galaxy

Reputation: 3400

Jekyll - Using relative URLs for post.url

I've recently upgraded to jekyll 1.0 and as a result post links now have a leading '/'.

Setting relative permalinks to true or false doesn't seem to change the generation of {{post.url}} at all, they always seem to come out with a leading slash.

I understand that I could use base_url, but I pass on the completed project to an organisation that ends up hosting it wherever (I don't know the URLs).

My config file that used to work was simply:

permalink: articles/:title

Any help would be great!

Upvotes: 8

Views: 5700

Answers (2)

idrumgood
idrumgood

Reputation: 4934

We noticed the same thing, and I tracked it down to the addition of baseUrl being exposed to liquid templates. In 0.12.1 baseUrl was not configurable in _config.yml and was defaulted to ''.

In 1.0.0 you could set it in the config and it defaults to '/' which is why you're seeing this. I don't believe it is a bug as it is still present in current (1.4.3) versions.

Upvotes: 2

Alan W. Smith
Alan W. Smith

Reputation: 25475

I'm seeing the same thing in Jekyll 1.0.3 install. Seems like a bug. Either way, a work around is to use a Liquid Filter to remove the first slash.

{{ post.url | remove_first:'/'}}

With the following pagination layout:

{% for post in paginator.posts %}
  <div class="postWrapper">
    <h2><a href="{{ post.url | remove_first:'/'}}">{{ post.title }}</a></h2>  
    <div class="postDate">{{ post.date | date:"%B %d, %Y" }}</div>
    <div class="postContent">{{ post.content }}</div>
  </div>
{% endfor %}

And your same _config.yml setting:

permalink: article/:title

Links are generated without the leading slash (e.g. <a href="article/the-title">The Title</a>).

Just be aware that if it is a bug and it gets fixed, you'll have to adjust your code to drop the 'remove_first' filter. Otherwise, it'll strip the slash in the middle of your link and break it that way.

Upvotes: 12

Related Questions