--
This commit is contained in:
@@ -118,7 +118,26 @@ async def default_response(request: Request, full_path: str) -> Response:
|
|||||||
accesscounter.increase()
|
accesscounter.increase()
|
||||||
return PlainTextResponse(markdown.text_content, status_code=200)
|
return PlainTextResponse(markdown.text_content, status_code=200)
|
||||||
else:
|
else:
|
||||||
response = templates.TemplateResponse(status_code=200, request=request, name=name)
|
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()
|
accesscounter.increase()
|
||||||
return response
|
return response
|
||||||
except TemplateNotFound:
|
except TemplateNotFound:
|
||||||
|
|||||||
Reference in New Issue
Block a user