-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
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
- Custom index pages
- similar issue Assertion error when using blog plugin #5880
- similar issue Blog plugin fails on standalone setup #5879
Reproduction
. venv/bin/activatepip install --upgrade --force-reinstall mkdocs-materialpip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.gitmkdocs 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).
- Create blog with build-in blugin
- Create post with category name (ex. "custom")
- Follow custom index page doc.:
- Take the URL generated by the built-in blog plugin (/blog/category/custom/)
- Create page with the same name (custom.md) in category directory as follows.
- Try build/serve again.
.
├─ docs/
│ └─ blog/
│ ├─ category/
│ │ └─ custom.md
│ ├─ posts/
│ └─ index.md
└─ mkdocs.yml
Browser
No response
Before submitting
- I have read and followed the bug reporting guidelines.
- I have attached links to the documentation, and possibly related issues and discussions.
- I assure that I have removed all customizations before submitting this bug report.
- I have attached a .zip file with a minimal reproduction.