Skip to content
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
15 changes: 11 additions & 4 deletions docs/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ def _workflow_source_link(example_content: str) -> str | None:
def _rewrite_sibling_workflow_links(readme: str) -> str:
"""Rewrite sibling workflow links to generated docs pages.

Only links to direct sibling workflow READMEs/directories are rewritten:
The generated workflow docs live under docs/workflows/gh-agent-workflows/.
Rewrite source-tree links so they resolve from that location:
- ../other-workflow/README.md -> other-workflow.md
- ../other-workflow/ -> other-workflow.md

Broader relative links (for example ../../docs/...) are intentionally left
unchanged.
- ../../docs/workflows/<page>.md -> ../<page>.md
"""

def replace_link(match: re.Match[str]) -> str:
Expand All @@ -66,6 +65,14 @@ def replace_link(match: re.Match[str]) -> str:
anchor = dir_match.group(2) or ""
return f"[{link_text}]({slug}.md{anchor})"

docs_workflows_match = re.fullmatch(
r"\.\./\.\./docs/workflows/([a-z0-9-]+)\.md(#.*)?", target
)
if docs_workflows_match:
slug = docs_workflows_match.group(1)
anchor = docs_workflows_match.group(2) or ""
return f"[{link_text}](../{slug}.md{anchor})"

return match.group(0)

return re.sub(r"\[([^\]]+)\]\(([^)]+)\)", replace_link, readme)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_docs_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_generate_page_rewrites_sibling_workflow_directory_link_with_anchor(tmp_
assert "../other-workflow/#details" not in page


def test_generate_page_preserves_non_sibling_docs_links(tmp_path):
def test_generate_page_rewrites_docs_workflows_links(tmp_path):
hooks = _load_hooks_module()
workflow_dir = _create_workflow_dir(
tmp_path,
Expand All @@ -57,5 +57,5 @@ def test_generate_page_preserves_non_sibling_docs_links(tmp_path):

page = hooks._generate_page(workflow_dir)

assert "[Detector / Fixer chaining](../../docs/workflows/detector-fixer-chaining.md)" in page
assert "../docs.mdworkflows/detector-fixer-chaining.md" not in page
assert "[Detector / Fixer chaining](../detector-fixer-chaining.md)" in page
assert "../../docs/workflows/detector-fixer-chaining.md" not in page
Loading