Skip to content

Commit a415a0c

Browse files
committed
Allow docs to be in staging_docs or docs
1 parent 80837fc commit a415a0c

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/pulp_docs/mkdocs_macros.py

+27-9
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,19 @@ def _place_doc_files(src_dir: Path, docs_dir: Path, repo: Repo, api_src_dir: Pat
190190

191191
try:
192192
shutil.copytree(
193-
src_dir / SRC_DOCS_DIRNAME,
193+
src_dir / "staging_docs",
194194
docs_dir / "docs",
195195
)
196+
repo.status.has_staging_docs = True
196197
except FileNotFoundError:
197-
Path(docs_dir / "docs").mkdir(parents=True)
198198
repo.status.has_staging_docs = False
199+
try:
200+
shutil.copytree(
201+
src_dir / "docs",
202+
docs_dir / "docs",
203+
)
204+
except FileNotFoundError:
205+
Path(docs_dir / "docs").mkdir(parents=True)
199206

200207
# Add index pages to User and Dev sections
201208
main_index = docs_dir / "docs/index.md"
@@ -398,9 +405,11 @@ def define_env(env):
398405
if feature_id in config.disabled:
399406
env.conf["plugins"][plugin_name].config["enabled"] = False
400407

401-
# Try to watch CWD/staging_docs
402-
watched_workdir = Path("staging_docs")
403-
if watched_workdir.exists():
408+
# Try to watch CWD/staging_docs or CWD/docs
409+
watched_workdir = next(
410+
(p for p in (Path("staging_docs"), Path("docs")) if p.exists()), None
411+
)
412+
if watched_workdir:
404413
env.conf["watch"].append(str(watched_workdir.resolve()))
405414

406415
# Pass relevant data for future processing
@@ -445,16 +454,25 @@ def on_pre_page_macros(env):
445454
repos: Repos = env.conf["pulp_repos"] # type: ignore
446455

447456
# Configure the edit_url with correct repository and path
448-
src_uri = env.page.file.src_uri.replace("/docs/", f"/{SRC_DOCS_DIRNAME}/")
457+
src_uri = env.page.file.src_uri
449458
if src_uri != "index.md":
450459
repo, _, path = src_uri.partition("/")
451460
else:
452461
repo = "pulpcore"
453-
path = f"{SRC_DOCS_DIRNAME}/index.md"
462+
path = "docs/index.md"
454463

455464
repo_obj = repos.get(repo)
456-
repo_branch = getattr(repo_obj, "branch", "main")
457-
edit_url = f"https://github.com/pulp/{repo}/edit/{repo_branch}/{path}"
465+
if repo_obj:
466+
if repo_obj.status.has_staging_docs:
467+
path = ("/" + path).replace("/docs/", "/staging_docs/")[1:]
468+
if isinstance(repo_obj, SubPackage):
469+
path = repo_obj.name + "/" + path
470+
repo = repo_obj.subpackage_of
471+
repo_obj = repos.get(repo)
472+
repo_branch = getattr(repo_obj, "branch", "main")
473+
edit_url = f"https://github.com/pulp/{repo}/edit/{repo_branch}/{path}"
474+
else:
475+
edit_url = None
458476
env.page.edit_url = edit_url
459477

460478

0 commit comments

Comments
 (0)