Navigation and index.html and / and DOMAIN


#1

I’m using
{% if page.url == item.link %} active{% endif %}

And ideas how I can deal with

  • domain.ext/index.html
  • domain.ext/
  • domain.ext

#2

for my home page i do:

<a class="nav-item nav-link{% if page.active %} active{% endif %}" href="/">Home</a>

and then in the front matter for that page only i have:
active: true


#3

I host on AWS S3, these both resolve to domain.ext
Probably could get index to redirect as well, but there are no links that have it so I don’t see how any one would arrive there other than manually typing it.


#4

I normalize the page.url first (as shown in https://github.com/flutter/website/blob/edbbd0761be3f4049c6de627980720159c2d584f/src/_includes/head.html#L16):

{% assign page_url = page.url | regex_replace: '/index$|/index.html$|\.html$|/$' -%}

#5
  1. First of all you must have a navigation.yml file in a _data folder. Your navigation.yml should be like this:
links:
- name: Home
  link: /
- name: Another link
  link: /another-link/
- name: And so on
  link: /and-so-on/
  1. Second, your navigation.html will be like this:
<div class="nav">
	<ul>
		{% for link in site.data.navigation.links %}
			{% assign class = "" %}
			{% if link.highlight %}
				{% assign class = class | append: " highlight" %}
			{% endif %}

			{% if link.link == page.url %}
				{% assign class = class | append: " active" %}
			{% endif %}
			<li>
                              <a href="{{ site.baseurl }}{{ link.link }}" 
                                   class="{{ class }}" 
                                   {% if link.new_window %}
                                   target="_blank"
                                   {% endif %}>
                                   {{ link.name }}
                              </a>
                      </li>
		{% endfor %}
	</ul>
</div>

  1. If my answer satisfies your question kindly marks the topic as resolved.