Skip to content

Commit de36bd3

Browse files
committed
Add Support for _SUMMARY.md files
1 parent c2c16ae commit de36bd3

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

mkdocs.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ repo_url: "https://github.com/pulp/pulp-docs"
44
repo_name: "pulp/pulp-docs"
55
edit_uri_template: "https://github.com/pulp/pulp-docs/edit/main/pulp_docs/{path}"
66

7-
docs_dir: "pulp_docs"
7+
docs_dir: "../pulp-docs/pulp_docs"
88
theme:
99
name: material
10-
custom_dir: "custom"
10+
custom_dir: "../pulp-docs/custom"
1111
logo: assets/pulp_logo_icon.svg
1212
favicon: assets/favicon.ico
1313
features:
@@ -51,7 +51,6 @@ nav:
5151
plugins:
5252
- PulpDocs:
5353
repositories:
54-
# TODO add all repositories...
5554
- title: "Pulpcore"
5655
path: "pulpcore"
5756
git_url: "https://github.com/pulp/pulpcore"

src/pulp_docs/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def build(self, config: Config, dry_run: bool = False):
9292
env = os.environ.copy()
9393
env.update(config.get_environ_dict())
9494
options = (
95-
("--config-file", config.mkdocs_file),
95+
("--config-file", str(config.mkdocs_file)),
9696
("--site-dir", str(Path("site").absolute())),
9797
)
9898

src/pulp_docs/plugin.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from mkdocs.config.defaults import MkDocsConfig
1111
from mkdocs.plugins import event_priority, get_plugin_logger, BasePlugin
1212
from mkdocs.structure.files import File, Files
13-
from mkdocs.structure.nav import Navigation, Section
13+
from mkdocs.structure.nav import Navigation, Section, Link
1414
from mkdocs.structure.pages import Page
1515
from mkdocs.utils.templates import TemplateContext
1616

@@ -36,24 +36,6 @@ class PulpDocsPluginConfig(Config):
3636
repositories = config_options.ListOfItems(RepositoryOption, default=[])
3737

3838

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-
5739
class RepositoryNav:
5840
def __init__(self, config: MkDocsConfig, repository_slug: Path):
5941
self._nav_file_name: str = config.plugins["literate-nav"].config.nav_file
@@ -70,10 +52,32 @@ def __init__(self, config: MkDocsConfig, repository_slug: Path):
7052

7153
self._extra_uris: list[Path] = []
7254

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+
7378
def add(self, src_uri: Path) -> None:
74-
# TODO Find and do something about the _SUMMARY.md files.
7579
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":
7781
if src_uri == self._user_index_uri:
7882
self._user_index_found = True
7983
elif src_uri == self._dev_index_uri:
@@ -98,8 +102,7 @@ def user_nav(self) -> list[t.Any]:
98102
{"Reference": []},
99103
]
100104
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)
103106
result.append({"Usage": user_nav})
104107

105108
admin_nav: list[t.Any] = [
@@ -109,8 +112,7 @@ def user_nav(self) -> list[t.Any]:
109112
{"Reference": []},
110113
]
111114
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)
114116
result.append({"Administration": admin_nav})
115117
result.extend(str(uri) for uri in self._extra_uris)
116118

@@ -127,8 +129,7 @@ def dev_nav(self) -> list[t.Any]:
127129
{"Reference": []},
128130
]
129131
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:])
132133
return result
133134

134135
def missing_indices(self) -> t.Iterator[Path]:
@@ -161,6 +162,8 @@ def _render_sitemap_item(nav_item: Page | Section) -> str:
161162
return f"<li>{title}<ul>{children}</ul></li>"
162163
else:
163164
return ""
165+
elif isinstance(nav_item, Link):
166+
return ""
164167
else:
165168
raise NotImplementedError(f"Unknown nav item {nav_item}")
166169

@@ -204,7 +207,6 @@ def repository_data(
204207

205208

206209
def rss_items() -> list:
207-
return []
208210
# that's Himdel's rss feed: https://github.com/himdel
209211
# TODO move this fetching to js.
210212
response = httpx.get("https://himdel.eu/feed/pulp-changes.json")

0 commit comments

Comments
 (0)