Loads of boiler plating
Some checks failed
Build, Push, and Deploy to Nomad / docker-nomad (push) Has been cancelled

This commit is contained in:
Henrik Jess
2024-12-10 17:09:37 +01:00
parent e7fdfb4967
commit 492d933119
6 changed files with 172 additions and 158 deletions

30
app.py
View File

@@ -20,17 +20,29 @@ with open("mock_data.json") as file:
# Index route
@app.get("/", response_class=HTMLResponse)
async def get_index(request: Request):
return templates.TemplateResponse("index.html", {"request": request, "data": data})
return templates.TemplateResponse(
"index.html",
{"request": request, "data": data, "page_title": "Forside", "author": "Henrik"}
)
# Category route
@app.get("/category/{category_name}", response_class=HTMLResponse)
async def get_category(request: Request, category_name: str):
category_file = f"data/{category_name}/index.html"
if os.path.exists(category_file):
with open(category_file) as file:
category_content = file.read()
return templates.TemplateResponse(
"category.html",
{"request": request, "category_name": category_name, "content": category_content}
)
# Find den korrekte kategori
category = next((cat for cat in data["categories"] if cat["path"] == category_name), None)
if category:
category_file = f"data/{category_name}/index.html"
if os.path.exists(category_file):
with open(category_file) as file:
category_content = file.read()
return templates.TemplateResponse(
"category.html",
{
"request": request,
"data": data,
"page_title": category["name"],
"author": category["author"],
"content": category_content
},
)
return HTMLResponse("Kategori ikke fundet", status_code=404)