Skip to content

Instantly share code, notes, and snippets.

@SetoAira
Created March 20, 2017 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SetoAira/d07f98623052b1f7ba079055de21a8f0 to your computer and use it in GitHub Desktop.
Save SetoAira/d07f98623052b1f7ba079055de21a8f0 to your computer and use it in GitHub Desktop.
Get relative path for jekyll.
{% assign dep = {{{{page.url | split:"/"}} | size }} %}{% assign dep = {{dep | minus:2 }} %}{% assign url_last1 = {{page.url | slice: -5, 5}} %}{% assign url_last2 = {{page.url | slice: -1, 1}} %}{% if url_last1 == '.html' or url_last2 == '/' %}{% assign dep = {{dep | plus:1 }} %}{% endif %}{% assign relative = '' %}{% if dep <= 0 %}{% assign relative = './' %}{% else %}{% for i in (1..dep) %}{% assign relative = {{relative | append:'../'}} %}{% endfor %}{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment