aaranxu / adidoks

AdiDoks is a mordern documentation theme, which is a port of the Hugo theme Doks for Zola.

Home Page:https://adidoks.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nav bar autogeneration

ejiektpobehuk opened this issue · comments

commented

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.

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.