oprypin / mkdocs-section-index

MkDocs plugin to allow clickable sections that lead to an index page
https://oprypin.github.io/mkdocs-section-index
MIT License
74 stars 7 forks source link

Having more than one page in a directory crashes now with `mkdocs-material` `v9.0.7` #13

Closed paveloom closed 1 year ago

paveloom commented 1 year ago

Here's a simple directory structure:

.
├── docs
│   └── test
│       ├── 1.md
│       └── 2.md
├── mkdocs.yml
├── pdm.lock
└── pyproject.toml

README.md and test.md are empty.

pyproject.toml:

[tool.pdm]

[project]
dependencies = [
    "mkdocs-material==9.0.7",
    "mkdocs-section-index==0.3.4",
]
requires-python = ">=3.11"
license = {text = "MIT"}

[tool.pdm.scripts]
mkdocs = "mkdocs"

mkdocs.yml:

site_name: My Docs
theme:
  name: material
plugins:
  - search
  - section-index

Calling pdm mkdocs serve:

INFO     -  Building documentation...
INFO     -  Cleaning site directory
Traceback (most recent call last):
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/mkdocs/__main__.py", line 234, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/mkdocs/commands/serve.py", line 83, in serve
    builder(config)
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/mkdocs/commands/serve.py", line 76, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/mkdocs/commands/build.py", line 320, in build
    _build_theme_template(template, env, files, config, nav)
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/mkdocs/commands/build.py", line 118, in _build_theme_template
    output = _build_template(template_name, template, files, config, nav)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/mkdocs/commands/build.py", line 97, in _build_template
    output = template.render(context)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/material/404.html", line 4, in top-level template code
    {% extends "main.html" %}
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/material/main.html", line 4, in top-level template code
    {% extends "base.html" %}
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/material/base.html", line 148, in top-level template code
    {% block site_nav %}
^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/material/base.html", line 156, in block 'site_nav'
    {% include "partials/nav.html" %}
^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/material/partials/nav.html", line 27, in top-level template code
    {% include "partials/nav-item.html" %}
^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/material/partials/nav-item.html", line 91, in top-level template code
    {{ render(nav_item, path, level) }}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/jinja2/runtime.py", line 777, in _invoke
    rv = self._func(*arguments)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/material/partials/nav-item.html", line 48, in template
    <nav class="md-nav" data-md-level="{{ level }}" aria-labelledby="{{ path }}_label" aria-expanded="{{ nav_item.active | tojson }}">
^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/jinja2/filters.py", line 1688, in do_tojson
    return htmlsafe_json_dumps(value, dumps=dumps, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/home/paveloom/Playground/mkdocs-material-issue/__pypackages__/3.11/lib/jinja2/utils.py", line 658, in htmlsafe_json_dumps
    dumps(obj, **kwargs)
  File "/usr/lib64/python3.11/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "/usr/lib64/python3.11/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Undefined is not JSON serializable

Works fine with mkdocs-material v9.0.6. Might be related to https://github.com/oprypin/mkdocs-section-index/issues/6.