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

Fix keep docs dir #89

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.6.1

### Prs in Release

- [Fix keep docs dir](https://github.com/jdoiro3/mkdocs-multirepo-plugin/pull/89)

## 0.6.0

### Prs in Release
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_multirepo_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def handle_repos_import(self, config: Config, repos: List[RepoConfig]) -> Config
or derived_edit_uri,
multi_docs=bool(import_stmt.get("multi_docs", False)),
extra_imports=import_stmt.get("extra_imports", []),
keep_docs_dir=import_stmt.get("keep_docs_dir", False),
keep_docs_dir=import_stmt.get("keep_docs_dir"),
)
)
asyncio_run(batch_import(docs_repo_objs))
Expand Down
19 changes: 12 additions & 7 deletions mkdocs_multirepo_plugin/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import shutil
import time
from pathlib import Path
from typing import Callable, Dict, List, Tuple, Union
from typing import Callable, Dict, List, Optional, Tuple, Union

from mkdocs.config import Config
from mkdocs.structure.files import File, Files, _filter_paths, _sort_files
Expand Down Expand Up @@ -149,7 +149,7 @@ def get_import_stmts(
multi_docs=bool(import_stmt.get("multi_docs", False)),
config=import_stmt.get("config", "mkdocs.yml"),
extra_imports=import_stmt.get("extra_imports", []),
keep_docs_dir=import_stmt.get("keep_docs_dir", False),
keep_docs_dir=import_stmt.get("keep_docs_dir"),
)
imports.append(NavImport(section, nav[index], repo))
path_to_section.pop()
Expand Down Expand Up @@ -231,6 +231,9 @@ class DocsRepo(Repo):
multi_docs (bool): If this is True, it means the repo has multiple docs directories that the user
wants to be pulled into the site.
extra_imports (list): Extra directories to import along with the docs.
keep_docs_dir (bool): If `True` the docs directory will be kept when importing docs from this repo,
if `False` it will be removed, and if `None` (default) it will fall back to
the global setting.
"""

def _fix_edit_uri(self, edit_uri: str) -> str:
Expand Down Expand Up @@ -259,7 +262,7 @@ def __init__(
multi_docs: bool = False,
config: str = "mkdocs.yml",
extra_imports: List[str] = None,
keep_docs_dir: bool = False,
keep_docs_dir: Optional[bool] = None,
*args,
**kwargs,
):
Expand Down Expand Up @@ -297,8 +300,10 @@ def __eq__(self, other):
def name_length(self):
return len(Path(self.name).parts)

def keep_docs_dir(self, global_config_val: bool = False):
return self._keep_docs_dir and (self._keep_docs_dir or global_config_val)
def keep_docs_dir(self, global_keep_docs_dir: bool = False):
if self._keep_docs_dir is None:
return global_keep_docs_dir
return self._keep_docs_dir

def get_edit_url(
self, src_path, keep_docs_dir: bool = False, nav_repos: bool = False
Expand All @@ -323,7 +328,7 @@ def get_edit_url(
]
elif (
is_extra_import
or self.keep_docs_dir(global_config_val=keep_docs_dir)
or self.keep_docs_dir(global_keep_docs_dir=keep_docs_dir)
or nav_repos
):
url_parts = [self.url, self.edit_uri, src_path]
Expand Down Expand Up @@ -377,7 +382,7 @@ async def import_docs(
self.transform_docs_dir()
else:
await self.sparse_clone([self.docs_dir, self.config] + self.extra_imports)
if not self.keep_docs_dir(global_config_val=keep_docs_dir):
if not self.keep_docs_dir(global_keep_docs_dir=keep_docs_dir):
await execute_bash_script(
"mv_docs_up.sh",
[self.docs_dir.replace("/*", "")],
Expand Down
Loading