8000 Built-in `blog` plugin give `AssertionError` with custom index pages · Issue #5896 · squidfunk/mkdocs-material · GitHub
[go: up one dir, main page]

Skip to content

Built-in blog plugin give AssertionError with custom index pages #5896

@balansczerni

Description

@balansczerni

Context

I'm trying to create a custom index page for blog categories.

Bug description

After creating a custom index page ("custom-category-page.md") for any of the blog categories (category: "custom-category-page"), I get the error:

INFO    -  Building documentation...
INFO    -  Cleaning site directory
Traceback (most recent call last):
  File "/Users/name/.pyenv/versions/3.11.4/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/mkdocs/__main__.py", line 270, in serve_command
    serve.serve(**kwargs)
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 86, in serve
    builder(config)
  File "/Users/name/.pyenv/versions/3.11.4/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 "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/mkdocs/commands/build.py", line 311, in build
    nav = config.plugins.on_nav(nav, config=config, files=files)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/mkdocs/plugins.py", line 536, in on_nav
    return self.run_event('nav', nav, config=config, files=files)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/mkdocs/plugins.py", line 507, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/material/plugins/blog/plugin.py", line 174, in on_nav
    views = [*self._generate_categories(config, files)]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/name/.pyenv/versions/3.11.4/lib/python3.11/site-packages/material/plugins/blog/plugin.py", line 597, in _generate_categories
    assert isinstance(file.page, Category)
AssertionError

Related code: (597-599)

                # Assign post to category and vice versa
                assert isinstance(file.page, Category)
                file.page.posts.append(post)
                post.categories.append(file.page)

The error appears whether I modify categories_url_format:. I got the same results with:

categories_url_format: {slug} (in my case)

.
├─ docs/
│  └─ blog/
│     └─ custom-category-page.md 

as with default categories_url_format: category/{slug}

.
├─ docs/
│  └─ blog/
│     ├─ category/
│     │  └─ custom-category-page.md 

According to the current documentation, this should allow me to add content to category pages:

If you want to add custom content to automatically generated archive and category indexes, e.g. to add a category description prior to the list of posts, you can manually create the category page in the same location where the built-in blog plugin would create it.

Related links

Reproduction

  • . venv/bin/activate
  • pip install --upgrade --force-reinstall mkdocs-material
  • pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git
  • mkdocs new .
  • mkdocs build

Minimal reproduction: insiders-custom-index-page-fail-raw.zip

additional version with modified categories_url_format settings which do not fix the error:

insiders-custom-index-page-fail.zip

Steps to reproduce

The bug affects the insiders version related features (blog customization).

  1. Create blog with build-in blugin
  2. Create post with category name (ex. "custom")
  3. Follow custom index page doc.:
    1. Take the URL generated by the built-in blog plugin (/blog/category/custom/)
    2. Create page with the same name (custom.md) in category directory as follows.
    3. Try build/serve again.
.
├─ docs/
│  └─ blog/
│     ├─ category/
│     │  └─ custom.md 
│     ├─ posts/
│     └─ index.md
└─ mkdocs.yml

Browser

No response

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open🏆 perfectIssue is of outstanding quality

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0