2 This is adapted from: https://ricostacruz.com/til/relative-paths-in-jekyll
4 `page.url` gives the URL of the current page with a leading /:
6 - when the URL ends with the extension (e.g., /foo/bar.html) then we can get
7 the depth by counting the number of / and remove - 1
8 - when the URL ends with a / (e.g. /foo/bar/) then the number / gives the depth
12 {% assign relative_root_path = '' %}
14 {% assign last_char = page.url | slice: -1 %}
16 {% if last_char == "/"}
17 {% assign offset = 0 %}
19 {% assign offset = 1 %}
22 {% assign depth = page.url | split: '/' | size | minus: offset %}
23 {% if depth <= 1 %}{% assign relative_root_path = '.' %}
24 {% elsif depth == 2 %}{% assign relative_root_path = '..' %}
25 {% elsif depth == 3 %}{% assign relative_root_path = '../..' %}
26 {% elsif depth == 4 %}{% assign relative_root_path = '../../..' %}