Skip to content

Commit

Permalink
fix ssh urls to https
Browse files Browse the repository at this point in the history
  • Loading branch information
galamdring committed Feb 20, 2025
1 parent 78132fa commit 8416ecf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.8.4

### Prs in Release

- [Fix SSH urls to HTTPS](https://github.com/jdoiro3/mkdocs-multirepo-plugin/pull/171)

## 0.8.3

### Prs in Release
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,24 @@ Once you're done configuring, run either `mkdocs serve` or `mkdocs build`. This

## Additional Features

### Support ssh urls for import

If an imported repo is imported via an ssh connection, the edit url needs to be modified to reflect an https link.

```
plugins:
- search
- awesome-pages
- multirepo:
cleanup: false
repos:
- section: Some MKDocs Repo
section_path: mkdocs
import_url: 'ssh://[email protected]/mkdocs/some-repo?branch=main&edit_uri=blob/main/docs'
```
This url is modified to remove the `ssh://git@` or `git@` with `https://` creating the correct edit url.
### α Multiple Docs Directories in Imported Repo (Alpha)
If an imported repo is a monorepo (i.e., has multiple *docs* directories), *multirepo* automatically includes them in the site when `multi_docs` is set to `True`.
Expand Down
16 changes: 12 additions & 4 deletions mkdocs_multirepo_plugin/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ 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_https_url(self, source_url: str) -> str:
"""Converts a git url to an https url"""
if source_url.startswith("ssh://"):
source_url = source_url.replace("ssh://", "")
if source_url.startswith("git@"):
source_url = source_url.replace(":", "/").replace("git@", "https://")
return source_url

def get_edit_url(
self, src_path, keep_docs_dir: bool = False, nav_repos: bool = False
Expand All @@ -319,14 +327,14 @@ def get_edit_url(
if parent_path in self.src_path_map:
src_path = Path(src_path)
url_parts = [
self.url,
self.get_https_url(self.url),
self.edit_uri,
self.src_path_map.get(parent_path),
str(src_path.name),
]
else:
url_parts = [
self.url,
self.get_https_url(self.url),
self.edit_uri,
self.src_path_map.get(str(src_path), str(src_path)),
]
Expand All @@ -335,10 +343,10 @@ def get_edit_url(
or self.keep_docs_dir(global_keep_docs_dir=keep_docs_dir)
or nav_repos
):
url_parts = [self.url, self.edit_uri, src_path]
url_parts = [self.get_https_url(self.url), self.edit_uri, src_path]
else:
url_parts = [
self.url,
self.get_https_url(self.url),
self.edit_uri,
self.docs_dir.replace("/*", ""),
src_path,
Expand Down

0 comments on commit 8416ecf

Please sign in to comment.