Add /help routes to display README documentation

Provides /help index and /help/{doc_name} routes to view
L1 server and Common library READMEs in the web UI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
giles
2026-01-11 11:29:49 +00:00
parent c9c4a340fd
commit dd3d5927f5

View File

@@ -3682,6 +3682,84 @@ async def download_client():
) )
# ============================================================================
# Help / Documentation Routes
# ============================================================================
L2_DOCS_DIR = Path(__file__).parent
COMMON_DOCS_DIR = Path(__file__).parent.parent / "common"
L2_DOCS_MAP = {
"l2": ("L2 Server (ActivityPub)", L2_DOCS_DIR / "README.md"),
"common": ("Common Library", COMMON_DOCS_DIR / "README.md"),
}
@app.get("/help", response_class=HTMLResponse)
async def help_index(request: Request):
"""Documentation index page."""
username = get_user_from_cookie(request)
# Build doc links
doc_links = ""
for key, (title, path) in L2_DOCS_MAP.items():
if path.exists():
doc_links += f'''
<a href="/help/{key}" class="block p-6 bg-dark-600 rounded-lg hover:bg-dark-500 transition-colors">
<h2 class="text-xl font-semibold text-white mb-2">{title}</h2>
<p class="text-gray-400">View documentation</p>
</a>
'''
content = f'''
<div class="max-w-4xl mx-auto">
<h1 class="text-2xl font-bold text-white mb-6">Documentation</h1>
<div class="grid gap-4">
{doc_links}
</div>
</div>
'''
return HTMLResponse(base_html("Help", content, username))
@app.get("/help/{doc_name}", response_class=HTMLResponse)
async def help_page(doc_name: str, request: Request):
"""Render a README as HTML."""
if doc_name not in L2_DOCS_MAP:
raise HTTPException(404, f"Documentation '{doc_name}' not found")
title, doc_path = L2_DOCS_MAP[doc_name]
if not doc_path.exists():
raise HTTPException(404, f"Documentation file not found")
username = get_user_from_cookie(request)
# Read and render markdown
md_content = doc_path.read_text()
html_content = markdown.markdown(md_content, extensions=['tables', 'fenced_code'])
content = f'''
<div class="max-w-4xl mx-auto">
<div class="mb-4">
<a href="/help" class="text-blue-400 hover:underline">&larr; Back to Help</a>
</div>
<div class="prose prose-invert max-w-none
prose-headings:text-white prose-headings:border-b prose-headings:border-dark-500 prose-headings:pb-2
prose-h1:text-2xl prose-h1:mt-0
prose-h2:text-xl prose-h2:mt-6
prose-a:text-blue-400 hover:prose-a:text-blue-300
prose-pre:bg-dark-600 prose-pre:border prose-pre:border-dark-500
prose-code:bg-dark-600 prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:text-green-300
prose-table:border-collapse
prose-th:bg-dark-600 prose-th:border prose-th:border-dark-500 prose-th:px-4 prose-th:py-2
prose-td:border prose-td:border-dark-500 prose-td:px-4 prose-td:py-2">
{html_content}
</div>
</div>
'''
return HTMLResponse(base_html(title, content, username))
if __name__ == "__main__": if __name__ == "__main__":
import uvicorn import uvicorn
uvicorn.run("server:app", host="0.0.0.0", port=8200, workers=4) uvicorn.run("server:app", host="0.0.0.0", port=8200, workers=4)