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

Category and Archive Error #6270

Closed
4 tasks done
userofgithub023897 opened this issue Nov 1, 2023 · 2 comments
Closed
4 tasks done

Category and Archive Error #6270

userofgithub023897 opened this issue Nov 1, 2023 · 2 comments
Labels
bug Issue reports a bug resolved by config change Issue can be mitigated by the reporter

Comments

@userofgithub023897
Copy link

Context

If some use in Markdown sites in front matter more than 10 (estimation) times

  • the same category
  • the same MM/YYYY (e.g. 2022-12-16)

the server stops and throws an error.

Bug description

mkdocs serve

...

ERROR   -  Error building page 'blog/archive/2022/12/page/2.md': Archive(title='Dezember 2022',
           url='/blog/archive/2022/12/') is not in list
Traceback (most recent call last):
  File "/opt/homebrew/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/__main__.py", line 270, in serve_command
    serve.serve(**kwargs)
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 86, in serve
    builder(config)
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 67, in builder
    build(config, live_server=None if is_clean else server, dirty=is_dirty)
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/commands/build.py", line 349, in build
    _build_page(
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/commands/build.py", line 222, in _build_page
    context = config.plugins.on_page_context(context, page=page, config=config, nav=nav)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/plugins.py", line 583, in on_page_context
    return self.run_event('page_context', context, page=page, config=config, nav=nav)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mkdocs/plugins.py", line 507, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/material/plugins/blog/plugin.py", line 328, in on_page_context
    items[items.index(prev)] = page
          ^^^^^^^^^^^^^^^^^
ValueError: Archive(title='Dezember 2022', url='/blog/archive/2022/12/') is not in list

Related links

Reproduction

9.4.7-archive-category-bug.zip

Steps to reproduce

If category and archive in the mkdocs.yml are set to false the mkdocs serve runs without any issue.

  • categories: false
  • archive: false

The tags plugin as reported in #5952 works fine. The same tag name can be used unlimited times in the Markdown files in front matter.

plugins:
  - blog:

...

      categories: false

...

      archive: false

Browser

Chrome, Firefox, Other

Before submitting

@squidfunk squidfunk added the bug Issue reports a bug label Nov 2, 2023
@squidfunk
Copy link
Owner

squidfunk commented Nov 2, 2023

Thanks for reporting. Indeed, there seems to be some issue with pagination. Temporary mitigation: Raise the number of items per page in pagination:

plugins:
  - blog:
      pagination_per_page: 1000

@squidfunk
Copy link
Owner

squidfunk commented Nov 2, 2023

Okay, so there are two things at play here:

  1. You linked the blog/index.md as a page, not a section. This is not recommended, because now the archive and category pages cannot be correctly mounted, which is why our documentation does not recommend this.

  2. The crashing is caused by this line:

    # If we're not building a standalone blog, the entrypoint will always
    # have a parent when it is included in the navigation. The parent is
    # essential to correctly resolve the location where the archive and
    # category views are attached. If the entrypoint doesn't have a parent,
    # we know that the author did not include it in the navigation, so we
    # explicitly mark it as not included.
    if not self.blog.parent and self.config.blog_dir != ".":
    self.blog.file.inclusion = InclusionLevel.NOT_IN_NAV

    This was added in 50c273c to fix Blog plugin fails with StopIteration when no nav entry is present #6041nav is defined but the blog is not included, which might happen during development.

We cannot remove the line, because then #6041 will not work anymore, but we should definitely catch the fact that the blog is not correctly linked in the navigation. MkDocs 1.6 will include some changes that are related to inclusion levels, so any changes we make now will likely not work then, because it looks like MkDocs 1.6 might be a big, breaking release. For this reason, we will wait until 1.6 is out and then see if we can mitigate the problem.

In the meantime, please use the following nav structure to mitigate the issue:

nav:
  - Home: index.md
  - Blog:
    - blog/index.md
  - Archive: assets/archive.md
  - Tags Cloud: assets/tags.md

@squidfunk squidfunk added the resolved by config change Issue can be mitigated by the reporter label Nov 2, 2023
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
Projects
None yet
Development

No branches or pull requests

2 participants