Skip to content

Commit 262165d

Browse files
authored
Section-level re-structures (#19)
* Remove (global) Reference section in favor of persona-scoped reference sections * Improve sections overviews * add quicklinks table * Improve help page
1 parent 35840cb commit 262165d

File tree

17 files changed

+639
-35
lines changed

17 files changed

+639
-35
lines changed

Diff for: src/pulp_docs/mkdocs_macros.py

+40-10
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def prepare_repositories(TMPDIR: Path, repos: Repos, config: Config):
101101
this_src_dir = repo_sources / repo_or_pkg.subpackage_of / repo_or_pkg.name
102102

103103
# install and post-process
104-
_install_doc_files(this_src_dir, this_docs_dir, repo_or_pkg)
104+
_place_doc_files(this_src_dir, this_docs_dir, repo_or_pkg)
105105
if repo_or_pkg.type == "content":
106106
_generate_rest_api_page(this_docs_dir, repo_or_pkg.name, repo_or_pkg.title)
107107

@@ -122,7 +122,7 @@ def prepare_repositories(TMPDIR: Path, repos: Repos, config: Config):
122122
return (repo_docs, repo_sources)
123123

124124

125-
def _install_doc_files(src_dir: Path, docs_dir: Path, repo: Repo):
125+
def _place_doc_files(src_dir: Path, docs_dir: Path, repo: Repo):
126126
"""Copy only doc-related files from src_dir to doc_dir"""
127127
log.info(f"Moving doc files:\nfrom '{src_dir}'\nto '{docs_dir}'")
128128

@@ -131,15 +131,24 @@ def _install_doc_files(src_dir: Path, docs_dir: Path, repo: Repo):
131131
except FileNotFoundError:
132132
Path(docs_dir / "docs").mkdir(parents=True)
133133
repo.status.has_staging_docs = False
134-
try:
135-
shutil.copy(src_dir / "CHANGELOG.md", docs_dir / "CHANGELOG.md")
136-
except FileNotFoundError:
137-
repo.status.has_changelog = False
138134

139-
try:
140-
shutil.copy(src_dir / "README.md", docs_dir / "README.md")
141-
except FileNotFoundError:
142-
repo.status.has_readme = False
135+
# Get CHANGELOG
136+
# TODO: remove reading .rst (plugins should provide markdown CHANGELOG)
137+
repo.status.has_changelog = False
138+
changes_dir = Path(docs_dir / "changes")
139+
changes_dir.mkdir(exist_ok=True)
140+
for changelog_name in ("CHANGELOG.md", "CHANGES.md", "CHANGES.rst"):
141+
changelog_path = Path(src_dir / changelog_name)
142+
if changelog_path.exists():
143+
shutil.copy(changelog_path, changes_dir / "changelog.md")
144+
repo.status.has_changelog = True
145+
return
146+
147+
# Create placeholder, case it was not possible to fetch one
148+
empty_changelog = changes_dir / "changelog.md"
149+
empty_changelog.write_text(
150+
"# Changelog\n\nThe repository does not provide a changelog or there was a problem fetching it."
151+
)
143152

144153

145154
def _generate_rest_api_page(docs_dir: Path, repo_name: str, repo_title: str):
@@ -243,8 +252,29 @@ def define_env(env):
243252

244253
log.info("[pulp-docs] Done with pulp-docs.")
245254
env.conf["pulp_repos"] = repos
255+
env.config["pulp_repos"] = repos
246256
env.conf["pulp_config"] = config
247257

258+
# Extra config
259+
@env.macro
260+
def get_repos(repo_type="content"):
261+
"Return repo names by type"
262+
_repo_type = [repo_type] if repo_type else None
263+
repos_list = sorted(
264+
repos.get_repos(repo_types=_repo_type), key=lambda x: x.title
265+
)
266+
repos_data = [
267+
{
268+
"title": repo.title,
269+
"version": "3.12.1",
270+
"rest_api_url": f"https://docs.pulpproject.org/{repo.name}/restapi.html",
271+
"codebase_url": f"https://github.com/{repo.owner}/{repo.name}",
272+
"changelog_url": f"site:{repo.name}/changes/changelog/",
273+
}
274+
for repo in repos_list
275+
]
276+
return repos_data
277+
248278

249279
def on_pre_page_macros(env):
250280
"""The mkdocs-macros hook just before an inidvidual page render."""

Diff for: src/pulp_docs/navigation.py

+25-21
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,8 @@ def grouped_by_persona(tmpdir: Path, repos: Repos):
5656
{content-type}
5757
"""
5858
f = AgregationUtils(tmpdir, repos)
59-
help_section = [
60-
{"Overview": f.section_file("help/index.md")},
61-
{
62-
"Bugs, Feature and Backport Requests": f.section_file(
63-
"help/bugs-features.md"
64-
)
65-
},
66-
]
6759
usage_section = [
68-
{"Overview": f.section_file("usage/index.md")},
60+
{"Overview": f.section_file("user/index.md")},
6961
{
7062
"Pulpcore": [
7163
f.section(
@@ -113,7 +105,7 @@ def grouped_by_persona(tmpdir: Path, repos: Repos):
113105
),
114106
]
115107
development_section = [
116-
{"Overview": f.section_file("development/index.md")},
108+
{"Overview": f.section_file("dev/index.md")},
117109
{
118110
"Pulpcore": [
119111
f.section(
@@ -126,26 +118,38 @@ def grouped_by_persona(tmpdir: Path, repos: Repos):
126118
]
127119
},
128120
{
129-
"Plugins": f.repo_grouping(
130-
"{repo}/docs/dev/{content}", repo_types=["content"]
131-
)
132-
},
121+
"Plugins": f.repo_grouping( "{repo}/docs/dev/{content}", repo_types=["content"] ) },
133122
{"Extras": f.repo_grouping("{repo}/docs/dev/{content}", repo_types=["other"])},
134123
]
135-
reference_section = [
136-
{"Overview": f.section_file("reference/index.md")},
137-
{"Repository Map": f.section_file("reference/01-repository-map.md")},
138-
{"Glossary": f.section_file("reference/02-glossary.md")},
139-
{"Repositories": f.repo_reference_grouping()},
124+
help_section = [
125+
*f.get_children("pulp-docs/docs/sections/help/community"),
126+
{"Documentation Usage": f.get_children("pulp-docs/docs/sections/help/using-this-doc")},
127+
{
128+
"Changelogs": [
129+
{"Pulpcore": "pulpcore/changes/changelog.md"},
130+
{
131+
"Plugins": sorted(
132+
f.repo_grouping(
133+
"{repo}/changes", repo_types=["content"]
134+
).items()
135+
)
136+
},
137+
{
138+
"Extra": sorted(
139+
f.repo_grouping("{repo}/changes", repo_types=["other"]).items()
140+
)
141+
},
142+
]
143+
},
144+
{"Governance": f.get_children("pulp-docs/docs/sections/help/governance")},
140145
]
141146

142147
# Main Section
143148
navigation = [
144149
{"Home": "index.md"},
145150
{"User Manual": usage_section},
146151
{"Admin Manual": admin_section},
147-
{"Development": development_section},
148-
{"Reference": reference_section},
152+
{"Developer Manual": development_section},
149153
{"Help": help_section},
150154
]
151155
return navigation

Diff for: src/pulp_docs/repository.py

+4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ class SubPackage:
203203
local_basepath = None
204204
branch_in_use = ""
205205
branch = ""
206+
owner = ""
207+
208+
def __post_init__(self):
209+
self.owner = self.subpackage_of
206210

207211

208212
@dataclass

Diff for: src/pulp_docs/utils/aggregation.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import typing as t
33
from pathlib import Path
4+
import re
45

56
from pulp_docs.constants import Names
67
from pulp_docs.repository import Repos
@@ -67,7 +68,7 @@ def repo_grouping(
6768
6869
Arguments:
6970
template_str: The template with fields to expand. Accepts combination of '{repo}' and '{content}'
70-
repos: The set of repos to use. Accepts list with combination of "core", "content" and "other"
71+
repo_types: The set of repos to use. Accepts list with combination of "core", "content" and "other"
7172
content_types: The set of content-types to use. Accepts combination of "guides", "learn" and "tutorial"
7273
7374
Example:
@@ -93,7 +94,7 @@ def repo_grouping(
9394

9495
# Selected a set of repos
9596
selected_repos = []
96-
selected_content = content_types or ["tutorials", "guides", "learn"]
97+
selected_content = content_types or ["tutorials", "guides", "learn", "reference"]
9798
if not repo_types: # default case
9899
selected_repos = self.repos.all
99100
else:
@@ -107,7 +108,7 @@ def repo_grouping(
107108
)
108109
_repo_content = self.get_children(lookup_path)
109110
if _repo_content:
110-
_nav[repo.title] = _repo_content
111+
_nav[repo.title] = _repo_content if len(_repo_content) > 1 else _repo_content[0]
111112
# Expand content-types
112113
else:
113114
for repo in selected_repos:
@@ -177,7 +178,7 @@ def repo_reference_grouping(self):
177178

178179
def section_file(self, section_and_filename: str):
179180
"""Get a markdown file from the website section folder."""
180-
basepath = "pulpcore/docs/sections"
181+
basepath = "pulp-docs/docs/sections"
181182
return f"{basepath}/{section_and_filename}"
182183

183184
def section_children(self, section_name: str):

Diff for: staging_docs/dev/reference/markdown-cheatsheet.md

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Markdown Cheatsheet
2+
3+
There are basic markdown features recommended for use in Pulp.
4+
5+
### Internal links
6+
7+
=== "Template"
8+
9+
```markdown
10+
[My Link](site:{repo-name}/docs/{persona}/{content-type}/some-page.md).
11+
```
12+
13+
=== "Sample"
14+
15+
```markdown
16+
[My Link](site:pulp-docs/docs/dev/reference/markdown-cheatsheet.md).
17+
```
18+
19+
=== "Sample Rendered"
20+
21+
```markdown
22+
[My Link](http://127.0.0.1:8000/pulp-docs/docs/dev/reference/markdown-cheatsheet/).
23+
```
24+
25+
- This is enabled by [mkdocs-site-urls](https://github.com/octoprint/mkdocs-site-urls) plugin.
26+
- This is preferred over *relative* links because of our complex structure. See tradeoffs [here](https://github.com/pedro-psb/pulp-docs/issues/2)
27+
28+
29+
### Codeblocks
30+
31+
32+
=== "Raw"
33+
34+
````
35+
```
36+
<location "/pulp/api/v3/foo_route">
37+
proxypass /pulp/api http://${pulp-api}/pulp/api
38+
proxypassreverse /pulp/api http://${pulp-api}/pulp/api
39+
requestheader set foo "asdf"
40+
</location>
41+
```
42+
````
43+
44+
---
45+
46+
```
47+
<location "/pulp/api/v3/foo_route">
48+
proxypass /pulp/api http://${pulp-api}/pulp/api
49+
proxypassreverse /pulp/api http://${pulp-api}/pulp/api
50+
requestheader set foo "asdf"
51+
</location>
52+
```
53+
54+
=== "Python Language"
55+
56+
````
57+
```python
58+
serializer = mymodelserializer(data=data)
59+
serializer.is_valid(raise_exception=true)
60+
instance = serializer.create(serializer.validated_data)
61+
```
62+
````
63+
64+
---
65+
66+
```python
67+
serializer = mymodelserializer(data=data)
68+
serializer.is_valid(raise_exception=true)
69+
instance = serializer.create(serializer.validated_data)
70+
```
71+
72+
=== "Python REPL"
73+
74+
````
75+
```python
76+
>>> serializer = mymodelserializer(data=data)
77+
>>> serializer.is_valid(raise_exception=true)
78+
>>> instance = serializer.create(serializer.validated_data)
79+
Some output
80+
```
81+
````
82+
83+
---
84+
85+
```python
86+
>>> serializer = mymodelserializer(data=data)
87+
>>> serializer.is_valid(raise_exception=true)
88+
>>> instance = serializer.create(serializer.validated_data)
89+
Some output
90+
```
91+
92+
=== "With 'Title'"
93+
94+
````
95+
```bash title="script.sh"
96+
pulp file repository update --name myrepo --retained-versions 1
97+
```
98+
````
99+
100+
---
101+
102+
```bash title="script.sh"
103+
pulp file repository update --name myrepo --retained-versions 1
104+
```
105+
106+
### Tabbed content
107+
108+
109+
<div class="grid" markdown>
110+
111+
````
112+
=== "Run"
113+
114+
```bash
115+
cat myfile.txt
116+
```
117+
118+
=== "Output"
119+
120+
```bash
121+
line1
122+
line2
123+
line3
124+
```
125+
````
126+
127+
=== "Run"
128+
129+
```bash
130+
cat myfile.txt
131+
```
132+
133+
=== "Output"
134+
135+
```bash
136+
line1
137+
line2
138+
line3
139+
```
140+
141+
</div>
142+
143+
- [See mkdocs-material](https://squidfunk.github.io/mkdocs-material/reference/content-tabs/#usage)
144+
- Each tab title must be in quotes
145+
- Each tab block must have 4 spaces of indent
146+
- Put space around `=== "Title"`
147+
148+
### Admonitions
149+
150+
[See mkdocs-material](https://squidfunk.github.io/mkdocs-material/reference/admonitions/#supported-types)
151+
152+
Use them wisely.
153+

Diff for: staging_docs/rest_api.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Rest API
2+
3+
The REST API reference for Pulp Plugins is generated using [ReDoc](https://redocly.com/redoc/) and are published in standalone pages:
4+
5+
<div class="grid cards" markdown>
6+
7+
{% for repo in get_repos() %}
8+
- <a href="https://docs.pulpproject.org/{{ repo.name }}/restapi.html" target="_blank">{{ repo.title }}</a>
9+
{% endfor %}
10+
11+
</div>

0 commit comments

Comments
 (0)