Skip to content

Commit a64f736

Browse files
committed
Make the section-pages URLs cleaner and repo-independent
1 parent 14bf1f2 commit a64f736

File tree

4 files changed

+25
-62
lines changed

4 files changed

+25
-62
lines changed

src/pulp_docs/constants.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""Project constants."""
2+
3+
SECTION_REPO = "pulp-docs"
4+
"""The repository which contains section pages"""
5+
16
ADMIN_NAME = "admin"
27
USER_NAME = "user"
38
RESTAPI_URL_TEMPLATE = "https://docs.pulpproject.org/{}/restapi.html"

src/pulp_docs/mkdocs_macros.py

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from pulp_docs.cli import Config
3030
from pulp_docs.navigation import get_navigation
31+
from pulp_docs.constants import SECTION_REPO
3132
from pulp_docs.repository import Repo, Repos, SubPackage
3233
from pulp_docs.utils.general import get_git_ignored_files
3334

@@ -165,6 +166,8 @@ def _place_doc_files(src_dir: Path, docs_dir: Path, repo: Repo, api_src_dir: Pat
165166
"""
166167
Copy only doc-related files from src_dir to doc_dir.
167168
169+
This effectively make it possible to control the url design.
170+
168171
Examples:
169172
```
170173
# src_dir
@@ -188,6 +191,13 @@ def _place_doc_files(src_dir: Path, docs_dir: Path, repo: Repo, api_src_dir: Pat
188191
Path(docs_dir / "docs").mkdir(parents=True)
189192
repo.status.has_staging_docs = False
190193

194+
# Setup section pages (for better urls)
195+
if repo.name == SECTION_REPO:
196+
shutil.copytree(
197+
docs_dir / "docs" / "sections", docs_dir.parent, dirs_exist_ok=True
198+
)
199+
shutil.rmtree(docs_dir / "docs" / "sections")
200+
191201
# Setup rest Api
192202
if has_restapi(repo):
193203
api_json = api_src_dir / f"{repo.name}/api.json"

src/pulp_docs/navigation.py

+8-60
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
from __future__ import annotations
2929

3030
from pathlib import Path
31-
from typing import List
3231

33-
from pulp_docs.constants import Names
3432
from pulp_docs.repository import Repos
3533
from pulp_docs.utils.aggregation import AgregationUtils
3634

@@ -58,82 +56,32 @@ def grouped_by_persona(tmpdir: Path, repos: Repos):
5856
{content-type}
5957
"""
6058
f = AgregationUtils(tmpdir, repos)
61-
SECTION_HOST = "pulp-docs"
6259

6360
# Manual section for each persona
6461
TEMPLATE_STR = "{repo}/docs/{persona}/{content}"
6562
manual_nav = {
6663
"user": [
67-
{"Overview": f"{SECTION_HOST}/docs/sections/user/index.md"},
68-
*f.repo_grouping(TEMPLATE_STR, personas=["user", "admin"])
64+
{"Overview": "user/index.md"},
65+
*f.repo_grouping(TEMPLATE_STR, personas=["user", "admin"]),
6966
],
7067
"dev": [
71-
{"Overview": f"{SECTION_HOST}/docs/sections/dev/index.md"},
72-
*f.repo_grouping(TEMPLATE_STR, personas=["dev"])
68+
{"Overview": "dev/index.md"},
69+
*f.repo_grouping(TEMPLATE_STR, personas=["dev"]),
7370
],
7471
}
7572

7673
# Custom help section
7774
help_section = [
78-
{"Overview": f"{SECTION_HOST}/docs/sections/help/index.md"},
79-
{"Community": f"{SECTION_HOST}/docs/sections/help/community/"},
80-
{"More": f"{SECTION_HOST}/docs/sections/help/more/"},
75+
{"Overview": "help/index.md"},
76+
{"Community": "help/community/"},
77+
{"More": "help/more/"},
8178
]
8279

83-
# Main Section
84-
# pulpcore_nav = manual_nav["user"][1]["Core"][0]
85-
# pulpcore_nav = create_repo_toc_index(pulpcore_nav)
86-
# print(pulpcore_nav)
87-
# manual_nav["user"][1]["Core"][0] = pulpcore_nav
88-
8980
navigation = [
9081
{"Home": "index.md"},
9182
{"User Manual": manual_nav["user"]},
9283
{"Developer Manual": manual_nav["dev"]},
93-
{"Blog": ["pulp-docs/docs/sections/blog/index.md"]},
84+
{"Blog": ["blog/index.md"]},
9485
{"Help": help_section},
9586
]
9687
return navigation
97-
98-
99-
def create_repo_toc_index(repo_nav: List[dict]):
100-
"""
101-
TODO: maybe try to leverage site-map
102-
103-
Create a toc with the format: {tuple-path: file-path}
104-
105-
Sample input:
106-
{'Pulp Core': [{'User': [{'Tutorials': 'pulpcore/docs/user/tutorials/'},
107-
{'How-to Guides': 'pulpcore/docs/user/guides/'},
108-
{'Learn More': 'pulpcore/docs/user/learn/'}]},
109-
{'Admin': [{'How-to Guides': 'pulpcore/docs/admin/guides/'},
110-
{'Learn More': 'pulpcore/docs/admin/learn/'}]},
111-
{'REST API': 'pulpcore/restapi.md'},
112-
{'Changelog': 'pulpcore/changes.md'}]}
113-
"""
114-
115-
def is_nav(item):
116-
return isinstance(item, list)
117-
118-
# {dir-path: page-str}
119-
toc = {}
120-
path = []
121-
122-
def recursive_add(nav):
123-
for name, item in nav.items():
124-
path.append(name)
125-
if isinstance(item, list):
126-
for entry in item:
127-
recursive_add(entry)
128-
path.pop()
129-
elif isinstance(item, dict):
130-
item_name, entry = item.items()
131-
path.append(item_name)
132-
recursive_add(entry)
133-
toc[tuple(path)] = None
134-
path.pop()
135-
else:
136-
toc[tuple(path)] = item
137-
138-
recursive_add(repo_nav)
139-
return toc

staging_docs/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ hide:
4040

4141
Learn why important projects rely on Pulp to manage the lifecyle of huge *Software Content* collections.
4242

43-
[:octicons-arrow-right-24: Features](site:pulp-docs/docs/sections/help/more/why-pulp/)
43+
[:octicons-arrow-right-24: Features](site:help/more/why-pulp/)
4444

4545
- :octicons-people-16:{ .lg .middle } **Get Involved**
4646

4747
---
4848

4949
Join our communication channels and get to know the contributors and users of Pulp's strong ecosystem.
5050

51-
[:octicons-arrow-right-24: Community](site:pulp-docs/docs/sections/help/community/get-involved/)
51+
[:octicons-arrow-right-24: Community](site:help/community/get-involved/)
5252

5353
</div>

0 commit comments

Comments
 (0)