Issue with navigation links not including baseurl

Im wondering why the following code doesn’t append the baseurl set in _config to my navigation links?

# _config

baseurl     : "/blog"
# theme data file

navigation:
  main:
  - title: About
    url: /about/

  - title: Blog
    url: /archive/

// navigation.html

 <nav class="nowrap overflow-x-auto">
    {% for link in site.data.theme.navigation.main %}

      {% if link.url contains 'http' or 'mailto' %}
        {% assign domain = '' %}
      {% else %}
        {% assign domain = site.url | append: site.baseurl %}
      {% endif %}

      <a href="{{ domain }}{{ link.url }}" class="{% if page.header.navigation == 'fancy' %}white hover-white dim{% else %}black hover-black{% endif %} link f4 f5-l fw3 mr3 mt2" {% if link.url contains 'http' %}target="_blank"{% endif %}>{{ link.title }}</a>

    {% endfor %}
</nav>

Here is my my repo

looking at your repo that is not what you have baseurl set to, are you building locally?

If you are using jekyll serve and working locally I think that baseurl is ignored as jekyll is trying to help you do local dev - if the baseurl value was used locally it may break all the links.

Assuming you are using jekyll serve, try jekyll build and look and see if it is doing it correctly - though build will not give you a web server preview.

1 Like

Hey Ron, appreciate the help.

Sorry, i should have been more specific.

Yes i am building the site locally. The _docs folder contains the demo of the theme (Live theme demo here). I am using the repo version of the theme e.g gem "minimal-jekyll-theme", :path => "../" because i have not updated the theme gem yet due to this navigation issue with baseurl. You will need to edit the gemfile with this change if you want to try this out yourself locally.

If you are using jekyll serve and working locally I think that baseurl is ignored as jekyll is trying to help you do local dev - if the baseurl value was used locally it may break all the links.

Baseurl is applied locally when using jekyll serve, just not to the navigation (see demo above specifically the site title link/post links on homepage include baseurl /minimal-jekyll-theme/).

Assuming you are using jekyll serve, try jekyll build and look and see if it is doing it correctly - though build will not give you a web server preview.

I can confirm same issue with jekyll build when i checked the nav code.

Do you think i may have found a Jekyll bug?

It appears that contain does not play well with or
I resolved this by adding an elsif branch as a workaround…:

    {% if link.url contains 'http' %}
      {% assign domain = '' %}
    {% elsif link.url contains 'mailto' %}
      {% assign domain = '' %}
    {% else %}
      {% assign domain = site.url | append: site.baseurl %}
    {% endif %}
1 Like

Thats perfect! Thanks a million @ashmaroli

1 Like

you’re welcome @desiredpersona :slight_smile:

1 Like