|
@@ -9,8 +9,39 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
|
from pydantic import BaseModel
|
|
|
import uvicorn
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
+import markdown
|
|
|
+from fastapi import Request, APIRouter
|
|
|
+from fastapi.responses import HTMLResponse
|
|
|
+from fastapi.templating import Jinja2Templates
|
|
|
+templates = Jinja2Templates(directory="templates")
|
|
|
+def openfile(filename):
|
|
|
+ filepath = os.path.join("page/", filename)
|
|
|
+ with open(filepath, "r", encoding="utf-8") as input_file:
|
|
|
+ text = input_file.read()
|
|
|
|
|
|
-app = FastAPI(description="長慶運通系統設計")
|
|
|
+ html = markdown.markdown(text)
|
|
|
+ data = {
|
|
|
+ "page": html
|
|
|
+ }
|
|
|
+ return data
|
|
|
+
|
|
|
+description = """
|
|
|
+長慶運通系統設計
|
|
|
+
|
|
|
+## Items
|
|
|
+
|
|
|
+You can **read items**.
|
|
|
+
|
|
|
+## Users
|
|
|
+
|
|
|
+![This image doesn't work](/imgs/datamodel.svg)
|
|
|
+
|
|
|
+You will be able to:
|
|
|
+
|
|
|
+* **Create users** (_not implemented_).
|
|
|
+* **Read users** (_not implemented_).
|
|
|
+"""
|
|
|
+app = FastAPI(description=description)
|
|
|
app.mount("/imgs", StaticFiles(directory="imgs"), name="imgs")
|
|
|
origins = [
|
|
|
"http://www.googo.org",
|
|
@@ -29,6 +60,13 @@ app.add_middleware(
|
|
|
allow_headers=["*"],
|
|
|
)
|
|
|
|
|
|
+@app.get("/page/{page_name}", response_class=HTMLResponse)
|
|
|
+async def show_page(request: Request, page_name: str):
|
|
|
+ data = openfile(page_name+".md")
|
|
|
+ print(data)
|
|
|
+ return templates.TemplateResponse("page.html", {"request": request, "data": data})
|
|
|
+
|
|
|
+
|
|
|
class q_req(BaseModel):
|
|
|
domain_name: str
|
|
|
|