Skip to content

Commit

Permalink
Allow selecting only directories using a wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed May 17, 2021
1 parent f0d223e commit dd6b402
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
13 changes: 8 additions & 5 deletions mkdocs_literate_nav/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ def make_nav(
error += "Did not find any title specified." + _EXAMPLES
elif out_item is None:
if "*" in out_title:
out_item = _Wildcard(
posixpath.normpath(posixpath.join(roots[0], out_title).lstrip("/"))
)
norm = posixpath.normpath(posixpath.join(roots[0], out_title).lstrip("/"))
if out_title.endswith("/"):
norm += "/"
out_item = _Wildcard(norm)
out_title = None
else:
error += "Did not find any item/section content specified." + _EXAMPLES
Expand All @@ -188,10 +189,9 @@ def make_nav(
if not isinstance(top_item, _Wildcard):
resolved.append(entry)
continue
for item in globber.glob(top_item):
for item in globber.glob(top_item.rstrip("/")):
if item in seen_items:
continue
seen_items.add(item)
if globber.isdir(item):
title = mkdocs.utils.dirname_to_title(posixpath.basename(item))
try:
Expand All @@ -200,7 +200,10 @@ def make_nav(
log.warning(f"{e} ({item!r})")
resolved.append({title: item})
else:
if top_item.endswith("/"):
continue
resolved.append({None: item})
seen_items.add(item)
return resolved


Expand Down
2 changes: 1 addition & 1 deletion tests/markdown_to_nav/wildcard/test_basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ files:
- section2/item.md
navs:
/: |
* *
- *
output:
- null: item1.md
- null: item2.md
Expand Down
13 changes: 13 additions & 0 deletions tests/markdown_to_nav/wildcard/test_dirs_then_files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
files:
- item1.md
- item2.md
- section2/item.md
navs:
/: |
- */
- *.md
output:
- Section2:
- null: section2/item.md
- null: item1.md
- null: item2.md

0 comments on commit dd6b402

Please sign in to comment.