22import os
33import pathlib
44import re
5+ from typing import Union
56from urllib .parse import urlsplit
67
78import igittigitt
1415from . import util as LOG
1516from .plugin_config import PluginConfig
1617
18+ NavigationItem = Union [MkDocsPage , MkDocsSection , MkDocsLink , None ]
19+
1720
1821class Judger :
1922 def __init__ (self , plugin_config : PluginConfig , mkdocs_config : MkDocsConfig ):
@@ -26,14 +29,15 @@ def __init__(self, plugin_config: PluginConfig, mkdocs_config: MkDocsConfig):
2629 pathlib .Path (self .plugin_config .mkdocsignore_file )
2730 )
2831
29- def evaluate_nav (self , nav ) :
32+ def evaluate_nav (self , nav : NavigationItem ) -> NavigationItem :
3033 if isinstance (nav , MkDocsSection ):
3134 nev_section = [self .evaluate_nav (child ) for child in nav .children ]
3235 nev_section = list (filter (lambda item : item is not None , nev_section ))
3336 if nev_section != []:
3437 return MkDocsSection (nav .title , nev_section )
3538 else :
3639 LOG .debug (f"remove navigation section: { nav .title } " )
40+ return None
3741 else :
3842 scheme , netloc , path , query , fragment = urlsplit (nav .url )
3943 if (
@@ -42,7 +46,8 @@ def evaluate_nav(self, nav):
4246 and not scheme
4347 and not netloc
4448 ):
45- LOG .debug (f"remove navigation item: { nav .title } { nav .url } " )
49+ LOG .debug (f"remove navigation link: { nav .title } { nav .url } " )
50+ return None
4651 else :
4752 return nav
4853
0 commit comments