Skip to content

Instantly share code, notes, and snippets.

@Ketrel

Ketrel/relBase.html

Last active May 18, 2020
Embed
What would you like to do?
Relative url base for jekyll
{% assign relBase = '' %}
{% assign tempDepth = page.url | append: 'hackish-solution' | split: '/' | size | minus: 2 %}
{% for i in (1..tempDepth) %}
{% assign relBase = relBase | append: "../" %}
{% endfor %}
{% if relBase == '' %}
{% assign relBase = './' %}
{% endif %}
@jeremytarpley

This comment has been minimized.

Copy link

@jeremytarpley jeremytarpley commented Jan 2, 2019

This saved me a bunch of time today, THANK YOU!

@u451f

This comment has been minimized.

Copy link

@u451f u451f commented Nov 23, 2019

Thanks indeed!

@Sakrecoer

This comment has been minimized.

Copy link

@Sakrecoer Sakrecoer commented Dec 12, 2019

Thanks a milion!
Since all of my frontmatter has leading / in their address i went ahead adapted it a bit by adding a condition

{% assign relBase = '' %}
{% assign tempDepth = page.url | append: 'hackish-solution' | split: '/' | size | minus: 2 %}
{% for i in (1..tempDepth) %}
  {% if forloop.last %}
    {% assign relBase = relBase | append: ".." %}
  {% else %}
    {% assign relBase = relBase | append: "../" %}
  {% endif %}
{% endfor %}
{% if relBase == '' %}
    {% assign relBase = '.' %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.