10
10
from mkdocs .config .defaults import MkDocsConfig
11
11
from mkdocs .plugins import event_priority , get_plugin_logger , BasePlugin
12
12
from mkdocs .structure .files import File , Files
13
- from mkdocs .structure .nav import Navigation , Section
13
+ from mkdocs .structure .nav import Navigation , Section , Link
14
14
from mkdocs .structure .pages import Page
15
15
from mkdocs .utils .templates import TemplateContext
16
16
@@ -36,24 +36,6 @@ class PulpDocsPluginConfig(Config):
36
36
repositories = config_options .ListOfItems (RepositoryOption , default = [])
37
37
38
38
39
- def _add_to_taxonomy_nav (
40
- src_uri : Path ,
41
- taxonomy_nav : list [t .Any ],
42
- ) -> bool :
43
- if src_uri .parts [3 ] == "tutorials" :
44
- taxonomy_nav [0 ]["Tutorials" ].append (str (src_uri ))
45
- elif src_uri .parts [3 ] == "guides" :
46
- taxonomy_nav [1 ]["How-to Guides" ].append (str (src_uri ))
47
- elif src_uri .parts [3 ] == "learn" :
48
- taxonomy_nav [2 ]["Learn More" ].append (str (src_uri ))
49
- elif src_uri .parts [3 ] == "reference" :
50
- taxonomy_nav [3 ]["Reference" ].append (str (src_uri ))
51
- else :
52
- log .info (f"Could not navigate { src_uri } ." )
53
- return False
54
- return True
55
-
56
-
57
39
class RepositoryNav :
58
40
def __init__ (self , config : MkDocsConfig , repository_slug : Path ):
59
41
self ._nav_file_name : str = config .plugins ["literate-nav" ].config .nav_file
@@ -70,10 +52,32 @@ def __init__(self, config: MkDocsConfig, repository_slug: Path):
70
52
71
53
self ._extra_uris : list [Path ] = []
72
54
55
+ def _add_to_taxonomy_nav (
56
+ self ,
57
+ src_uri : Path ,
58
+ taxonomy_nav : list [t .Any ],
59
+ obj : t .Any = None ,
60
+ ) -> None :
61
+ obj = obj or str (src_uri )
62
+ if src_uri .parts [3 ] == "tutorials" :
63
+ k1 , k2 = 0 , "Tutorials"
64
+ elif src_uri .parts [3 ] == "guides" :
65
+ k1 , k2 = 1 , "How-to Guides"
66
+ elif src_uri .parts [3 ] == "learn" :
67
+ k1 , k2 = 2 , "Learn More"
68
+ elif src_uri .parts [3 ] == "reference" :
69
+ k1 , k2 = 3 , "Reference"
70
+ else :
71
+ log .info (f"Could not navigate { src_uri } ." )
72
+ return
73
+ if len (src_uri .parts ) == 5 and src_uri .name == self ._nav_file_name :
74
+ taxonomy_nav [k1 ][k2 ] = str (src_uri .parent ) + "/"
75
+ if isinstance (taxonomy_nav [k1 ][k2 ], list ):
76
+ taxonomy_nav [k1 ][k2 ].append (obj )
77
+
73
78
def add (self , src_uri : Path ) -> None :
74
- # TODO Find and do something about the _SUMMARY.md files.
75
79
assert src_uri .parts [0 ] == str (self ._repository_slug )
76
- if src_uri .suffix == ".md" and not src_uri . name == self . _nav_file_name :
80
+ if src_uri .suffix == ".md" :
77
81
if src_uri == self ._user_index_uri :
78
82
self ._user_index_found = True
79
83
elif src_uri == self ._dev_index_uri :
@@ -98,8 +102,7 @@ def user_nav(self) -> list[t.Any]:
98
102
{"Reference" : []},
99
103
]
100
104
for src_uri in self ._user_uris :
101
- # TODO filter for literate nav
102
- _add_to_taxonomy_nav (src_uri , user_nav )
105
+ self ._add_to_taxonomy_nav (src_uri , user_nav )
103
106
result .append ({"Usage" : user_nav })
104
107
105
108
admin_nav : list [t .Any ] = [
@@ -109,8 +112,7 @@ def user_nav(self) -> list[t.Any]:
109
112
{"Reference" : []},
110
113
]
111
114
for src_uri in self ._admin_uris :
112
- # TODO filter for literate nav
113
- _add_to_taxonomy_nav (src_uri , admin_nav )
115
+ self ._add_to_taxonomy_nav (src_uri , admin_nav )
114
116
result .append ({"Administration" : admin_nav })
115
117
result .extend (str (uri ) for uri in self ._extra_uris )
116
118
@@ -127,8 +129,7 @@ def dev_nav(self) -> list[t.Any]:
127
129
{"Reference" : []},
128
130
]
129
131
for src_uri in self ._dev_uris :
130
- # TODO filter for literate nav
131
- _add_to_taxonomy_nav (src_uri , result [1 :])
132
+ self ._add_to_taxonomy_nav (src_uri , result [1 :])
132
133
return result
133
134
134
135
def missing_indices (self ) -> t .Iterator [Path ]:
@@ -161,6 +162,8 @@ def _render_sitemap_item(nav_item: Page | Section) -> str:
161
162
return f"<li>{ title } <ul>{ children } </ul></li>"
162
163
else :
163
164
return ""
165
+ elif isinstance (nav_item , Link ):
166
+ return ""
164
167
else :
165
168
raise NotImplementedError (f"Unknown nav item { nav_item } " )
166
169
@@ -204,7 +207,6 @@ def repository_data(
204
207
205
208
206
209
def rss_items () -> list :
207
- return []
208
210
# that's Himdel's rss feed: https://github.com/himdel
209
211
# TODO move this fetching to js.
210
212
response = httpx .get ("https://himdel.eu/feed/pulp-changes.json" )
0 commit comments