jbms / sphinx-immaterial

Adaptation of the popular mkdocs-material material design theme to the sphinx documentation system
https://jbms.github.io/sphinx-immaterial/
Other
196 stars 29 forks source link

Split navigation block into main and toc #151

Closed martinberoiz closed 2 years ago

martinberoiz commented 2 years ago

I maintain a repo with a modified theme for sphinx-immaterial. This is a suggestion to split the navigation block in base.html into navigation and toc. It would help me with the sub-theming.

Right now:

          <!-- Navigation -->
          {% block site_nav %}

            <!-- Main navigation -->
            {% if nav %}
              {% if page and page.meta and page.meta.hide %}
                {% set hidden = "hidden" if "navigation" in page.meta.hide %}
              {% endif %}
              <div
                class="md-sidebar md-sidebar--primary"
                data-md-component="sidebar"
                data-md-type="navigation"
                {{ hidden }}
              >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    {% include "partials/nav.html" %}
                  </div>
                </div>
              </div>
            {% endif %}

            <!-- Table of contents -->
            {% if not "toc.integrate" in features %}
              {% if page and page.meta and page.meta.hide %}
                {% set hidden = "hidden" if "toc" in page.meta.hide %}
              {% endif %}
              <div
                class="md-sidebar md-sidebar--secondary"
                data-md-component="sidebar"
                data-md-type="toc"
                {{ hidden }}
              >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    {% include "partials/toc.html" %}
                  </div>
                </div>
              </div>
            {% endif %}
          {% endblock %}

My proposed change (or similar):

          <!-- Navigation -->
          {% block site_nav %}

            <!-- Main navigation -->
            {% block site_nav_main %}
            {% if nav %}
              {% if page and page.meta and page.meta.hide %}
                {% set hidden = "hidden" if "navigation" in page.meta.hide %}
              {% endif %}
              <div
                class="md-sidebar md-sidebar--primary"
                data-md-component="sidebar"
                data-md-type="navigation"
                {{ hidden }}
              >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    {% include "partials/nav.html" %}
                  </div>
                </div>
              </div>
            {% endif %}
            {% endblock %}

            <!-- Table of contents -->
            {% block site_nav_toc %}
            {% if not "toc.integrate" in features %}
              {% if page and page.meta and page.meta.hide %}
                {% set hidden = "hidden" if "toc" in page.meta.hide %}
              {% endif %}
              <div
                class="md-sidebar md-sidebar--secondary"
                data-md-component="sidebar"
                data-md-type="toc"
                {{ hidden }}
              >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    {% include "partials/toc.html" %}
                  </div>
                </div>
              </div>
            {% endif %}
            {% endblock %}
          {% endblock %}

This change will also be backwards-compatible. I can create a PR if you agree to the change.

2bndy5 commented 2 years ago

We don't want to modify the HTML templates in any significant manner. This is because it makes it harder to merge in updates from the mkdocs-material repo (our upstream source).

martinberoiz commented 2 years ago

I see. Ok, I'll override the whole thing then. Thanks for your quick reply.

jbms commented 2 years ago

You could potentially submit a PR to the upstream mkdocs-material project.

martinberoiz commented 2 years ago

Oh, that's right. I think I'll do that. Thanks.