This commit is contained in:
2026-04-15 03:09:53 +09:00
parent 9f36204878
commit 38d8532073
+19
View File
@@ -117,8 +117,27 @@ async def default_response(request: Request, full_path: str) -> Response:
markdown = markitdown.convert_stream(io.BytesIO(main.encode("utf-8")), file_extension=".html")
accesscounter.increase()
return PlainTextResponse(markdown.text_content, status_code=200)
else:
lightweight_header = request.headers.get("lightweight", "").lower()
if lightweight_header in ["1", "true", "y", "yes"]:
lightweight_mode = True
elif lightweight_header in ["0", "false", "n", "no"]:
lightweight_mode = False
else:
lightweight_mode = request.cookies.get("lightweight_mode", "") == "true"
if lightweight_mode:
source = templates.env.loader.get_source(templates.env, name)[0]
source = source.replace('{% extends "/base.html" %}', '{% extends "/base-light.html" %}')
content = templates.env.from_string(source).render(request=request)
response = Response(content=content, status_code=200, media_type="text/html")
response.set_cookie("lightweight_mode", "true", samesite="lax")
else:
response = templates.TemplateResponse(status_code=200, request=request, name=name)
if request.cookies.get("lightweight_mode", "") == "true":
response.set_cookie("lightweight_mode", "false", samesite="lax")
accesscounter.increase()
return response
except TemplateNotFound: