WIP: pathlib support
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from os import path
|
||||
from pathlib import Path
|
||||
|
||||
import aiofiles
|
||||
from fastapi.responses import HTMLResponse, Response
|
||||
@ -8,27 +8,21 @@ from modules.app import app
|
||||
|
||||
@app.get("/pages/matter.css", include_in_schema=False)
|
||||
async def page_matter():
|
||||
async with aiofiles.open(
|
||||
path.join("pages", "matter.css"), "r", encoding="utf-8"
|
||||
) as f:
|
||||
async with aiofiles.open(Path("pages/matter.css"), "r", encoding="utf-8") as f:
|
||||
output = await f.read()
|
||||
return Response(content=output)
|
||||
|
||||
|
||||
@app.get("/pages/{page}/{file}", include_in_schema=False)
|
||||
async def page_assets(page: str, file: str):
|
||||
async with aiofiles.open(
|
||||
path.join("pages", page, file), "r", encoding="utf-8"
|
||||
) as f:
|
||||
async with aiofiles.open(Path(f"pages/{page}/{file}"), "r", encoding="utf-8") as f:
|
||||
output = await f.read()
|
||||
return Response(content=output)
|
||||
|
||||
|
||||
@app.get("/", include_in_schema=False)
|
||||
async def page_home():
|
||||
async with aiofiles.open(
|
||||
path.join("pages", "home", "index.html"), "r", encoding="utf-8"
|
||||
) as f:
|
||||
async with aiofiles.open(Path("pages/home/index.html"), "r", encoding="utf-8") as f:
|
||||
output = await f.read()
|
||||
return HTMLResponse(content=output)
|
||||
|
||||
@ -36,7 +30,7 @@ async def page_home():
|
||||
@app.get("/register", include_in_schema=False)
|
||||
async def page_register():
|
||||
async with aiofiles.open(
|
||||
path.join("pages", "register", "index.html"), "r", encoding="utf-8"
|
||||
Path("pages/register/index.html"), "r", encoding="utf-8"
|
||||
) as f:
|
||||
output = await f.read()
|
||||
return HTMLResponse(content=output)
|
||||
|
Reference in New Issue
Block a user