mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-03-27 09:58:31 +07:00
Fix _get_by_type for Section
This commit is contained in:
committed by
Waylan Limberg
parent
b50f32f1c6
commit
00b62aa144
@@ -21,6 +21,11 @@ The current and past members of the MkDocs team.
|
||||
* [@d0ugal](https://github.com/d0ugal/)
|
||||
* [@waylan](https://github.com/waylan/)
|
||||
|
||||
## Version 1.1.3 (Under development)
|
||||
|
||||
* Bugfix: Properly process navigation child items in `_get_by_type` when
|
||||
filtering for sections (#2203).
|
||||
|
||||
## Version 1.1.2 (2020-05-14)
|
||||
|
||||
* Bugfix: Normalize IP addresses and change unsupported address error to a
|
||||
|
||||
@@ -172,7 +172,7 @@ def _get_by_type(nav, T):
|
||||
for item in nav:
|
||||
if isinstance(item, T):
|
||||
ret.append(item)
|
||||
elif item.children:
|
||||
if item.children:
|
||||
ret.extend(_get_by_type(item.children, T))
|
||||
return ret
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from mkdocs.structure.nav import get_navigation
|
||||
from mkdocs.structure.nav import get_navigation, _get_by_type, Section
|
||||
from mkdocs.structure.files import File, Files
|
||||
from mkdocs.structure.pages import Page
|
||||
from mkdocs.tests.base import dedent, load_config
|
||||
@@ -377,3 +377,18 @@ class SiteNavigationTests(unittest.TestCase):
|
||||
self.assertFalse(site_navigation.items[1].children[3].children[0].active)
|
||||
self.assertFalse(site_navigation.items[1].children[3].active)
|
||||
self.assertFalse(site_navigation.items[1].active)
|
||||
|
||||
def test_get_by_type_nested_sections(self):
|
||||
nav_cfg = [
|
||||
{'Section 1': [
|
||||
{'Section 2': [
|
||||
{'Page': 'page.md'}
|
||||
]}
|
||||
]}
|
||||
]
|
||||
cfg = load_config(nav=nav_cfg, site_url='http://example.com/')
|
||||
files = Files([
|
||||
File('page.md', cfg['docs_dir'], cfg['site_dir'], cfg['use_directory_urls'])
|
||||
])
|
||||
site_navigation = get_navigation(files, cfg)
|
||||
self.assertEqual(len(_get_by_type(site_navigation, Section)), 2)
|
||||
|
||||
Reference in New Issue
Block a user