Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow docs to be in staging_docs or docs #75

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/pulp_docs/mkdocs_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,19 @@ def _place_doc_files(src_dir: Path, docs_dir: Path, repo: Repo, api_src_dir: Pat

try:
shutil.copytree(
src_dir / SRC_DOCS_DIRNAME,
src_dir / "staging_docs",
docs_dir / "docs",
)
repo.status.has_staging_docs = True
except FileNotFoundError:
Path(docs_dir / "docs").mkdir(parents=True)
repo.status.has_staging_docs = False
try:
shutil.copytree(
src_dir / "docs",
docs_dir / "docs",
)
except FileNotFoundError:
Path(docs_dir / "docs").mkdir(parents=True)

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

# Try to watch CWD/staging_docs
watched_workdir = Path("staging_docs")
if watched_workdir.exists():
# Try to watch CWD/staging_docs or CWD/docs
watched_workdir = next(
(p for p in (Path("staging_docs"), Path("docs")) if p.exists()), None
)
if watched_workdir:
env.conf["watch"].append(str(watched_workdir.resolve()))

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

# Configure the edit_url with correct repository and path
src_uri = env.page.file.src_uri.replace("/docs/", f"/{SRC_DOCS_DIRNAME}/")
src_uri = env.page.file.src_uri
if src_uri != "index.md":
repo, _, path = src_uri.partition("/")
else:
repo = "pulpcore"
path = f"{SRC_DOCS_DIRNAME}/index.md"
path = "docs/index.md"

repo_obj = repos.get(repo)
repo_branch = getattr(repo_obj, "branch", "main")
edit_url = f"https://github.com/pulp/{repo}/edit/{repo_branch}/{path}"
if repo_obj:
if repo_obj.status.has_staging_docs:
path = ("/" + path).replace("/docs/", "/staging_docs/")[1:]
if isinstance(repo_obj, SubPackage):
path = repo_obj.name + "/" + path
repo = repo_obj.subpackage_of
repo_obj = repos.get(repo)
repo_branch = getattr(repo_obj, "branch", "main")
edit_url = f"https://github.com/pulp/{repo}/edit/{repo_branch}/{path}"
else:
edit_url = None
env.page.edit_url = edit_url


Expand Down