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

Blog plugin returns error when using section-index #7283

Closed
4 tasks done
thinkORo opened this issue Jun 21, 2024 · 6 comments
Closed
4 tasks done

Blog plugin returns error when using section-index #7283

thinkORo opened this issue Jun 21, 2024 · 6 comments
Labels
bug Issue reports a bug resolved by config change Issue can be mitigated by the reporter upstream Issue must be taken upstream

Comments

@thinkORo
Copy link

Context

To better (as with the material functionality) define my menu structure, I use literate-nav together with section-index.

Unfortunately, I get the following error when activating the blog plugin.

Bug description

Traceback (most recent call last):
  File "/home/oro/Program/mambaforge/envs/mkdocs/lib/python3.12/site-packages/mkdocs/livereload/__init__.py", line 211, in _build_loop
    self.builder()
  File "/home/oro/Program/mambaforge/envs/mkdocs/lib/python3.12/site-packages/mkdocs/commands/serve.py", line 67, in builder
    build(config, serve_url=None if is_clean else serve_url, dirty=is_dirty)
  File "/home/oro/Program/mambaforge/envs/mkdocs/lib/python3.12/site-packages/mkdocs/commands/build.py", line 299, in build
    nav = config.plugins.on_nav(nav, config=config, files=files)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oro/Program/mambaforge/envs/mkdocs/lib/python3.12/site-packages/mkdocs/plugins.py", line 596, in on_nav
    return self.run_event('nav', nav, config=config, files=files)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oro/Program/mambaforge/envs/mkdocs/lib/python3.12/site-packages/mkdocs/plugins.py", line 566, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oro/Program/mambaforge/envs/mkdocs/lib/python3.12/site-packages/material/plugins/blog/plugin.py", line 187, in on_nav
    for view in self._resolve_views(self.blog):
  File "/home/oro/Program/mambaforge/envs/mkdocs/lib/python3.12/site-packages/material/plugins/blog/plugin.py", line 496, in _resolve_views
    assert isinstance(next, View)
           ^^^^^^^^^^^^^^^^^^^^^^
AssertionError
ERROR   -  [07:16:33] An error happened during the rebuild. The server will appear stuck until build errors are resolved.

Related links

n/a

Reproduction

support.zip

Steps to reproduce

  1. Install related python packages: mkdocs-material, mkdocs-section-index, mkdocs-literate-nav
  2. Create a folder docs/blog/posts and add some blog posts md-files
  3. Enable plugins in mkdocs.yml: section-index, literate-nav, blog

Browser

Firefox

Before submitting

@squidfunk
Copy link
Owner

Thanks for reporting. I checked your reproduction (please see my remark below) and it is definitely related to the section index plugin. If you remove the plugin, the build completes without error. Note that we do not officially support this plugin, but we support basically the exact same functionality via the navigation.indexes feature. We recommend that you can use this instead, as it also does not mandate a third party plugin.

Also note that the literate nav plugin doesn't seem compatible with the blog plugin, which adds navigation entries dynamically. You can see that there are actually multiple competing entries. If you disable the plugin, the blog plugin works as expected. Please also report this to the maintainer of the literate nav plugin.

Next time, please use the info plugin which is mandatory – you actually checked the box but did not us it. The info plugin collects much more information than what you get by just zipping things up 😉 It helps us help you faster.

@squidfunk squidfunk added bug Issue reports a bug resolved by config change Issue can be mitigated by the reporter upstream Issue must be taken upstream labels Jun 21, 2024
@squidfunk
Copy link
Owner

I also checked the source of the section index plugin – the problem is here:

# The page becomes a section-page.
page.__class__ = SectionPage
assert isinstance(page, SectionPage)

The section index plugin extends the normal Page class with SectionPage, while the blog plugin does the same thing with its View class. This leads to an incompatibility that I believe cannot be easily fixed.

@thinkORo
Copy link
Author

Hi Martin (@squidfunk), thank you for your quick reply.

You mentioned "but we support basically the exact same functionality via the navigation.indexes feature" but there is a reason for using section index and "literate nav plugin".

I want to define a navigation structure based on my folder structure but with different title, like so:

docs

  • folder A
    • subfolder A1
    • subfolder A2
  • folder B
    • subfolder B1
    • subfolder B2

"folder A" should be named "PROJECTS" and "folder B" should be named "HOME" in the navigation. Is that possible with the original "navigation" configuration in mkdocs-material? I know that I could rename the folder from "folder A" to "PROJECT" but if I would do so I cannot define the order in the navigation.

@squidfunk
Copy link
Owner

I'm not sure, I'm not a user of literate nan, and, as said, it's not a plugin we officially support. You can ask on our discussion board for support, if you like – maybe there are other users that have achieved what you're asking for ☺️

@kamilkrzyskow
Copy link
Collaborator

kamilkrzyskow commented Jun 22, 2024

@thinkORo
You could try using the mkdocs-awesome-pages-plugin to set the order of navigation elements in a directory ignoring the standard alphabetical ordering.
But be aware that depending on the required "granularity" of the nav configuration the initial setup might require creating a few .pages files in each directory that needs custom nav ordering, later on the maintenance cost of it should be lower.

@thinkORo
Copy link
Author

@kamilkrzyskow I know it's a play on words but this plugin is, in this context, awesome. It doesn't reduce the effort to control the navigation that much as I have to define ".pages"-files.

But it increases the clearness in my mkdocs.yml enormously.

THANK YOU.

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 by config change Issue can be mitigated by the reporter upstream Issue must be taken upstream
3 participants