fix(docs): rewrite broken relative links in agent and command pages

Add rewrite_relative_links() to generate-docs.py that converts ../../
relative paths to absolute GitHub URLs. Sibling agent links (e.g.,
cs-foo.md → cs-bar.md) are preserved as local doc links. Regenerated
all agent pages with fixed references.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Reza Rezvani
2026-03-11 15:25:31 +01:00
parent 72df5ccf2f
commit d10d324d50
16 changed files with 97 additions and 62 deletions

View File

@@ -143,6 +143,39 @@ def strip_content(content):
return content
GITHUB_BASE = "https://github.com/alirezarezvani/claude-skills/tree/main"
def rewrite_relative_links(content, source_rel_path):
"""Rewrite relative markdown links (../../, ../) to absolute GitHub URLs.
Agent and command source files use relative paths like ../../product-team/SKILL.md
which break when rendered in the docs site. Convert them to GitHub source links.
"""
source_dir = os.path.dirname(source_rel_path)
def resolve_link(match):
text = match.group(1)
rel_target = match.group(2)
# Only rewrite relative paths that go up (../)
if not rel_target.startswith("../"):
return match.group(0)
# Resolve against source directory
resolved = os.path.normpath(os.path.join(source_dir, rel_target))
# Keep links to sibling .md files in the same docs directory
# e.g. agents/product/cs-foo.md linking to cs-bar.md (same-level agent docs)
# These resolve to agents/product/cs-bar.md — only keep if they're
# a docs page we generate (agent .md that isn't CLAUDE.md)
if (resolved.startswith("agents/") and resolved.count("/") == 1
and resolved.endswith(".md") and "CLAUDE" not in resolved):
# This is a sibling agent doc link — rewrite to flat docs slug
sibling = os.path.basename(resolved).replace(".md", "") + ".md"
return f"[{text}]({sibling})"
return f"[{text}]({GITHUB_BASE}/{resolved})"
return re.sub(r"\[([^\]]+)\]\((\.\.[^\)]+)\)", resolve_link, content)
def generate_skill_page(skill, domain_key):
"""Generate a docs page for a single skill."""
skill_md_path = skill["path"]
@@ -349,6 +382,7 @@ description: "All {skill_count} {domain_name} skills for Claude Code, Codex CLI,
content = f.read()
content_clean = strip_content(content)
content_clean = rewrite_relative_links(content_clean, rel)
page = f'''---
title: "{title}"
@@ -424,6 +458,7 @@ description: "All {agent_count} Claude Code agents — multi-skill orchestrators
content = f.read()
content_clean = strip_content(content)
content_clean = rewrite_relative_links(content_clean, rel)
page = f'''---
title: "/{cmd_name}"