Skip to content

Commit 418d703

Browse files
author
Artur Huk
committed
mkdocs fix
1 parent 99a9455 commit 418d703

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

.github/workflows/docs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
- uses: actions/checkout@v4
1717
- uses: actions/setup-python@v5
1818
with:
19-
python-version: 3.x
19+
python-version: '3.12'
20+
- run: pip install -r requirements.txt
2021
- run: pip install -r requirements.mk.txt
22+
- run: pip install -e .
2123
- run: mkdocs gh-deploy --force

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ plugins:
2020
- mkdocstrings:
2121
handlers:
2222
python:
23+
paths: [src]
2324
options:
2425
show_root_heading: true
2526
show_source: true

mkdocs_hooks.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ def on_page_markdown(markdown, page, config, **kwargs):
5454

5555
if uri.startswith("09-pages/samples/"):
5656
markdown = markdown.replace("](../docs/", "](../")
57+
58+
repo = (config.get("repo_url") or "").rstrip("/")
59+
if repo:
60+
def samples_repl(match: re.Match[str]) -> str:
61+
rest = match.group(1)
62+
head = rest.rstrip("/")
63+
kind = "blob" if head.endswith((".md", ".py", ".yaml", ".sql", ".sh", ".cmd", ".example")) or "." in head.split("/")[-1] else "tree"
64+
return f"]({repo}/{kind}/main/samples/{rest}"
65+
66+
markdown = re.sub(r"\]\((?:\.\./)*(?:\./)?samples/([^)]+)\)", samples_repl, markdown)
67+
# Also catch relative links that were rewritten by include-markdown plugin
68+
# They usually look like ../../../samples/...
69+
markdown = re.sub(r"\]\(\.\./\.\./\.\./samples/([^)]+)\)", samples_repl, markdown)
70+
5771
if uri == "09-pages/samples/index.md":
5872
for d in _SAMPLE_READMES:
5973
markdown = markdown.replace(f"]({d}/README.md)", f"]({d}.md)")

0 commit comments

Comments
 (0)