Skip to content

Commit 11ea5f1

Browse files
committed
Support index.md auto-discovery in repo namespace
1 parent 262165d commit 11ea5f1

File tree

7 files changed

+93
-23
lines changed

7 files changed

+93
-23
lines changed

src/pulp_docs/navigation.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,19 @@ def grouped_by_persona(tmpdir: Path, repos: Repos):
118118
]
119119
},
120120
{
121-
"Plugins": f.repo_grouping( "{repo}/docs/dev/{content}", repo_types=["content"] ) },
121+
"Plugins": f.repo_grouping(
122+
"{repo}/docs/dev/{content}", repo_types=["content"]
123+
)
124+
},
122125
{"Extras": f.repo_grouping("{repo}/docs/dev/{content}", repo_types=["other"])},
123126
]
124127
help_section = [
125128
*f.get_children("pulp-docs/docs/sections/help/community"),
126-
{"Documentation Usage": f.get_children("pulp-docs/docs/sections/help/using-this-doc")},
129+
{
130+
"Documentation Usage": f.get_children(
131+
"pulp-docs/docs/sections/help/using-this-doc"
132+
)
133+
},
127134
{
128135
"Changelogs": [
129136
{"Pulpcore": "pulpcore/changes/changelog.md"},

src/pulp_docs/utils/aggregation.py

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
2+
import re
23
import typing as t
34
from pathlib import Path
4-
import re
55

66
from pulp_docs.constants import Names
77
from pulp_docs.repository import Repos
@@ -94,7 +94,12 @@ def repo_grouping(
9494

9595
# Selected a set of repos
9696
selected_repos = []
97-
selected_content = content_types or ["tutorials", "guides", "learn", "reference"]
97+
selected_content = content_types or [
98+
"tutorials",
99+
"guides",
100+
"learn",
101+
"reference",
102+
]
98103
if not repo_types: # default case
99104
selected_repos = self.repos.all
100105
else:
@@ -103,39 +108,61 @@ def repo_grouping(
103108
# Dont expand content-types
104109
if not _expand_content_types:
105110
for repo in selected_repos:
106-
lookup_path = self.tmpdir / template_str.format(
107-
repo=repo.name, admin=Names.ADMIN, user=Names.USER
108-
)
111+
lookup_path = self._parse_template_str(template_str, repo.name)
109112
_repo_content = self.get_children(lookup_path)
110113
if _repo_content:
111-
_nav[repo.title] = _repo_content if len(_repo_content) > 1 else _repo_content[0]
114+
_nav[repo.title] = (
115+
_repo_content if len(_repo_content) > 1 else _repo_content[0]
116+
)
112117
# Expand content-types
113118
else:
114119
for repo in selected_repos:
115120
repo_nav = {}
121+
# Include index.md if present in staging_docs/{persona}/index.md
122+
persona_basepath = self._parse_template_str(
123+
template_str, repo.name, "placeholder"
124+
).parent
125+
index_path = persona_basepath / "index.md"
126+
if index_path.exists():
127+
repo_nav["Overview"] = str(index_path.relative_to(self.tmpdir))
128+
116129
for content_type in selected_content:
117-
lookup_path = self.tmpdir / template_str.format(
118-
repo=repo.name,
119-
admin=Names.ADMIN,
120-
user=Names.USER,
121-
content=content_type,
130+
# Get repo files from content-type and persona
131+
lookup_path = self._parse_template_str(
132+
template_str, repo.name, content_type
122133
)
123134
_repo_content = self.get_children(lookup_path)
124135

125-
# special treatment to quickstart tutorial
126-
if content_type.lower() == "tutorials":
127-
quickstart_file = self._pop_quickstart_from(_repo_content)
128-
if quickstart_file:
129-
repo_nav["Quickstart"] = quickstart_file # type: ignore
130-
131-
# doesnt render content-type section if no files inside
136+
# Prevent rendering content-type section if there are no files
132137
if _repo_content:
133138
content_type_name = Names.get(content_type)
134139
repo_nav[content_type_name] = _repo_content # type: ignore
135140
if repo_nav:
136141
_nav[repo.title] = repo_nav
137142
return _nav or ["#"]
138143

144+
def _parse_template_str(
145+
self, template_str: str, repo_name: str, content_type: t.Optional[str] = None
146+
) -> Path:
147+
"""
148+
Replace template_str with repo_name and content_type.
149+
150+
Additionally, normalized {admin} {user} and {dev} names:
151+
- {repo}/docs/dev/{content}
152+
- {repo}/docs/{admin}/{content} -> uses constant for {admin}
153+
154+
TODO: deprecate this method of template string and use dataclasses instead.
155+
"""
156+
kwargs = {
157+
"repo": repo_name,
158+
"admin": Names.ADMIN,
159+
"user": Names.USER,
160+
}
161+
if content_type:
162+
kwargs["content"] = content_type
163+
164+
return self.tmpdir / template_str.format(**kwargs)
165+
139166
def _pop_quickstart_from(self, pathlist: t.List[str]) -> t.Optional[str]:
140167
"""Get quickstart.md file from filelist with case and variations tolerance"""
141168
for path in pathlist:

staging_docs/dev/guides/.gitkeep

Whitespace-only changes.

staging_docs/dev/index.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Overview
2+
3+
## What it is
4+
5+
`pulp-docs` is a tool for serving and building an unified doc out of Pulp's Plugin Ecosystem.
6+
7+
The idea is that each repository should install `pulp-docs` and imediatelly be able run the unified website server.
8+
Also, this should be used for the production build.
9+
10+
It was developed as part of [The new Pulp "Unified Docs"](https://hackmd.io/eE3kG8qhT9eohRYbtooNww?view) project.
11+
12+
## How it works
13+
14+
Through a `mkdocs-macro-plugin` hook (called in early stages of mkdocs processing), we inject the following steps:
15+
16+
1. Read [`repolist.yml`](https://github.com/pedro-psb/pulp-docs/blob/main/src/pulp_docs/data/repolist.yml) packaged with `pulp-docs` to know which repos/urls to use
17+
1. Download and Place all source code required to dir under `tempfile.gettempdir()`
18+
- Uses `../{repo}` if available OR
19+
- Uses existing cached `{tmpdir}/{repo}` if available OR
20+
- Downloads from github
21+
1. Configure `mkdocs` through a hook: fix `mkdocstrings` config, generate navigation structure, etc
22+
23+
## Quickstart
24+
25+
Recommended way for daily usage:
26+
27+
=== "pipx"
28+
29+
```bash
30+
pipx install git+https://github.com/pedro-psb/pulp-docs --include-deps
31+
pulp-docs serve
32+
```
33+
34+
=== "pip"
35+
36+
```bash
37+
pip --user install git+https://github.com/pedro-psb/pulp-docs
38+
pulp-docs serve
39+
```

staging_docs/dev/learn/.gitkeep

Whitespace-only changes.

staging_docs/dev/tutorials/.gitkeep

Whitespace-only changes.

staging_docs/dev/tutorials/quickstart.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)