Skip to content

Commit

Permalink
modifying relative_root_path
Browse files Browse the repository at this point in the history
  • Loading branch information
catchSheep committed Jul 30, 2024
1 parent 384dbcf commit 10405ba
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions _includes/base_path.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@
both 'site.url' and 'site.baseurl' are empty.
This case is handled by the last 'else' in the code below.
The logic there follows the (adapted) instructions found at:
https://ricostacruz.com/til/relative-paths-in-jekyll
https://ricostacruz.com/til/relative-paths-in-jekyll

`page.url` gives the URL of the current page with a leading /:
`page.url` gives the URL of the current page with a leading /:

- when the URL ends with an extension (e.g., /foo/bar.html),
we can get the 'depth' of the page by counting the number of
forward slashes ('/') and subtracting 1
- when the URL ends with a forward slash (e.g. /foo/bar/),
we can get the depth of the page by counting the number of /
- when the URL ends with an extension (e.g., /foo/bar.html),
we can get the 'depth' of the page by counting the number of
forward slashes ('/') and subtracting 1
- when the URL ends with a forward slash (e.g. /foo/bar/),
we can get the depth of the page by counting the number of /
{%- endcomment -%}

{% if site.url %}
{% assign relative_root_path = site.baseurl %}
{% assign relative_root_path = site.baseurl %}
{% else %}
{% assign last_char = page.url | slice: -1 %}
{% if last_char == "/" %}
{% assign offset = 0 %}
{% else %}
{% assign offset = 1 %}
{% assign last_char = page.url | slice: -1 %}
{% if last_char == "/" %}
{% assign offset = 0 %}
{% else %}
{% assign offset = 1 %}
{% endif %}
{% assign depth = page.url | split: '/' | size | minus: offset %}
{% assign relative_root_path = '.' %}
{% endif %}
{% assign depth = page.url | split: '/' | size | minus: offset %}
{% if depth <= 1 %}{% assign relative_root_path='.' %} {% else %}{% capture relative_root_path %}..{% for i in
(3..depth) %}/..{% endfor %}{% endcapture %} {% endif %} {% endif %}

0 comments on commit 10405ba

Please sign in to comment.