aaranxu / adidoks

AdiDoks is a mordern documentation theme, which is a port of the Hugo theme Doks for Zola.
https://adidoks.org
MIT License
220 stars 80 forks source link

Nav bar autogeneration #5

Open ejiektpobehuk opened 3 years ago

ejiektpobehuk commented 3 years ago

In my application of this theme there is no authors directory and private-policy/_index.md is moved to private-policy.md. This allows to have an autogenerated navbar.

Example of a generator used in templates/macros/header.html

            {% set index = get_section(path="_index.md") -%}
            {% for sections in index.subsections -%}
              {% set section = get_section(path=sections) -%}
              {% if current_path %}
                {% set current_section = current_path | split(pat="/") | nth(n=1) -%}
              {% else %}
                {% set current_section = '/' -%}
              {% endif %}
              {% set stripped_section_path  = section.path | replace(from="/", to="") -%}
              <li class="nav-item{% if current_section==stripped_section_path %} active{% endif %}">
              <a class="nav-link" href="{{ section.permalink }}">
                {{ section.title }}
              </a>
            </li>
            {% endfor -%}

I find it to be a neat feature, but fallback strategy is not clear to me. What would you say about using embedded navbar when there are no sections in a content dir or a config file. When there are sections in the content dir, but not in the config file, we use them. Whet there are menu entries in the config we use only them even if there others in the sections folder.

aaranxu commented 3 years ago

In my application of this theme there is no authors directory and private-policy/_index.md is moved to private-policy.md. This allows to have an autogenerated navbar.

It's a good suggestion, and it's a good idea to get the section from the current_path. I will improve the code just like what you have done. If you have finished the code, welcome to pull a request to improve it. Thanks very much.