Skip to content

Commit

Permalink
Support empty path in Nav
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed May 15, 2024
1 parent 7baa032 commit d6f08a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mkdocs_gen_files/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def __setitem__(self, keys: str | tuple[str, ...], value: str):
if isinstance(keys, str):
keys = (keys,)
cur = self._data
if not keys:
raise ValueError(f"The navigation path must not be empty (got {keys!r})")
for key in keys:
if not isinstance(key, str):
raise TypeError(
Expand All @@ -43,7 +41,9 @@ def __setitem__(self, keys: str | tuple[str, ...], value: str):

def items(self) -> Iterable[Item]:
"""Allows viewing the nav as a flattened sequence."""
return self._items(self._data, 0)
if None in self._data:
yield self.Item(level=0, title="", filename=self._data[None])
yield from self._items(self._data, 0)

@classmethod
def _items(cls, data: Mapping, level: int) -> Iterable[Item]:
Expand Down
8 changes: 8 additions & 0 deletions tests/nav/test_nav_none.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
code: |
nav[()] = "index.md"
nav["a"] = "a/index.md"
nav["a", "b"] = "a/b.md"
output: |
* [](index.md)
* [a](a/index.md)
* [b](a/b.md)

0 comments on commit d6f08a1

Please sign in to comment.