Files

27 lines
1.1 KiB
Python
Raw Permalink Normal View History

import os
from fastapi import APIRouter, HTTPException
from app.core.config import settings
router = APIRouter(prefix="/docs", tags=["Documentation"])
@router.get("", summary="List markdown technical documentation files")
@router.get("/", include_in_schema=False)
def list_docs():
"""List all available markdown documentation files in frontend docs."""
if not os.path.exists(settings.DOCS_DIR):
return {"docs": []}
files = [f for f in sorted(os.listdir(settings.DOCS_DIR)) if f.endswith(".md")]
return {"docs": files}
@router.get("/{doc_filename}")
def get_doc(doc_filename: str):
"""Retrieve content of a specific markdown documentation file."""
if not doc_filename.endswith(".md"):
doc_filename += ".md"
file_path = os.path.join(settings.DOCS_DIR, doc_filename)
if not os.path.exists(file_path):
raise HTTPException(status_code=404, detail=f"Doc file '{doc_filename}' not found")
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
return {"filename": doc_filename, "content": content}