Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation indexes are not rendered correctly on the Blog index from the second page onwards #5972

Closed
4 tasks done
vedranmiletic opened this issue Sep 5, 2023 · 7 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@vedranmiletic
Copy link
Contributor

Context

No response

Bug description

When using blog plugin with navigation.indexes feature, only the first page of the Blog index has the correctly rendered navigation. Other pages of the Blog index are rendered as if the feature is not enabled.

Interestingly enough, this happens only when there is at least three pages of posts in the Blog index.

Blog archive is affected the same way. I haven't checked if categories are affected since we don't use them.

Additionally, if the tags plugin is enabled, the Tags page will exhibit the same behavior regarding the rendering of the Blog index in the navigation. I have not included this in the minimal example on purpose to keep it minimal, but it can be observed on our group website. I can prepare a less minimal example if needed.

Related links

Reproduction

9.2.8-navigation.zip

Steps to reproduce

  1. mkdocs serve
  2. look at the navigation in first page of the Blog index
  3. see it is rendered as intended
  4. navigate to the second or the third page
  5. see it is rendered as if it would be without navigation.indexes feature enabled

Browser

No response

Before submitting

@squidfunk squidfunk added the bug Issue reports a bug label Sep 5, 2023
@balansczerni
Copy link
Contributor

I guess I have the same error?

I thought it was because I set tags_extra_files. In my case, the error occurs when more than 10 files appear in the posts directory and only occurs with (and from location of) tags_extra_files.

It's hard for me to describe it better so I'm attaching a minimal reproduction:
9.2.8+insiders.4.40.4-blog-vs-indexes.zip

.
├─ docs/
│  └─ blog/
│     ├─ subset.md
│     ├─ posts/
│     └─ index.md
└─ mkdocs.yml

mkdocs.yml:

theme:
  name: material
  features:
    - navigation.indexes

plugins:
  #- info
  - blog
  - tags:
      tags_extra_files:
        blog/subset.md:
          - mytag

nav:
  - Page: index.md
  - Blog:
    - blog/index.md
    - Subset page: blog/subset.md  
  - Tags: tags.md

extra:
  tags:
    My tag: mytag

Zrzut ekranu 2023-09-7 o 19 14 24 Średni

Zrzut ekranu 2023-09-7 o 19 14 49 Średni

In addition, I think I have located the place in the code where the bug takes place (this is from nav-item.html with my comments):

{% macro render(nav_item, path, level) %}
  {% set class = "md-nav__item" %}
  {% if nav_item.active %}
    {% set class = class ~ " md-nav__item--active" %}
  {% endif %}
  {% if nav_item.children %}
    {% set indexes = [] %}
    {% if "navigation.indexes" in features %}
      {% for nav_item in nav_item.children %}
        {% if nav_item.is_index and not index is defined %}
          {% set _ = indexes.append(nav_item) %}
        {% endif %}
      {% endfor %}
      {% endif %}
  
    {% if "navigation.sections" in features and level == 1 + (
      "navigation.tabs" in features
    ) %}
      {% set class = class ~ " md-nav__item--section" %}
    {% elif not nav_item.active and "navigation.prune" in features %}
      {% set class = class ~ " md-nav__item--pruned" %}
      {% set prune = true %}
    {% endif %}
    <li class="{{ class }} md-nav__item--nested">
      {% if not prune %}
        {% set expanded = "navigation.expand" in features %}
        {% set active = nav_item.active or expanded %}
        {% set checked = "checked" if nav_item.active %}
        {% if expanded and not checked %}
          {% set indeterminate = "md-toggle--indeterminate" %}
        {% endif %}
        <input class="md-nav__toggle md-toggle {{ indeterminate }}" type="checkbox" id="{{ path }}" {{ checked }}>
        {% if not indexes %}
          <label class="md-nav__link" for="{{ path }}" id="{{ path }}_label" tabindex="0">
            {{ render_content(nav_item) }} 🆘 This is "extra" blog link.
            <span class="md-nav__icon md-icon"></span>
          </label>
        {% else %}
          {% set index = indexes | first %}
          {% set class = "md-nav__link--active" if index == page %}
          <div class="md-nav__link md-nav__container">
            <a href="{{ index.url | url }}" class="md-nav__link {{ class }}">
              {{ render_content(index, nav_item) }} ✅ This is proper link for blog.
            </a>
            {% if nav_item.children | length > 1 %}
              <label class="md-nav__link {{ class }}" for="{{ path }}">
                <span class="md-nav__icon md-icon"></span>
              </label>
            {% endif %}
          </div>
        {% endif %}

@squidfunk
Copy link
Owner

Thanks to both of you for the reproductions – we'll look into it asap!

@smokedlinq
Copy link

FYI this also affects non-blog sites.

@squidfunk
Copy link
Owner

Fixed in 433c137. Paginated views did not correctly check if the base view is an index page or not. Now, if the view is an index page (i.e. is called index.md or README.md), paginated pages are also generated as index pages.

@smokedlinq I'm not sure where or how this happens for non-blog sites, as the issue reported is exclusive to the blog plugin. Please open a new issue with a minimal reproduction, so we can look into it.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Sep 22, 2023
@squidfunk
Copy link
Owner

@vedranmiletic if this does not solve the problem for the tags plugin, please create a new issue.

@vedranmiletic
Copy link
Contributor Author

@squidfunk thanks, it seems to work correctly now, both for tags page and blog index pages after the first one.

@squidfunk
Copy link
Owner

Released as part of 9.4.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

4 participants