--
This commit is contained in:
@@ -108,6 +108,17 @@ async def default_response(request: Request, full_path: str) -> Response:
|
||||
markdown_mode = True
|
||||
full_path = full_path[:-3] + ".html"
|
||||
|
||||
lightweight_query = request.query_params.get("lightweight", "").lower()
|
||||
lightweight_header = request.headers.get("lightweight", "").lower()
|
||||
lightweight_signal = lightweight_query or lightweight_header
|
||||
|
||||
if lightweight_signal in ["1", "y", "yes", "true"]:
|
||||
lightweight_mode = True
|
||||
elif lightweight_signal in ["0", "n", "no", "false"]:
|
||||
lightweight_mode = False
|
||||
else:
|
||||
lightweight_mode = request.cookies.get("lightweight_mode", "") == "true"
|
||||
|
||||
if full_path in ["", "/"]:
|
||||
template_candidates = ["index.html"]
|
||||
elif full_path.endswith(".html"):
|
||||
@@ -123,19 +134,8 @@ async def default_response(request: Request, full_path: str) -> Response:
|
||||
main = str(soup.find("main")) if soup.find("main") else content
|
||||
markdown = markitdown.convert_stream(io.BytesIO(main.encode("utf-8")), file_extension=".html")
|
||||
accesscounter.increase()
|
||||
return PlainTextResponse(markdown.text_content, status_code=200)
|
||||
return PlainTextResponse(markdown.text_content, status_code=200, media_type="text/markdown")
|
||||
else:
|
||||
lightweight_header = request.headers.get("lightweight", "").lower()
|
||||
lightweight_query = request.query_params.get("lightweight", "").lower()
|
||||
lightweight_signal = lightweight_header or lightweight_query
|
||||
|
||||
if lightweight_signal in ["1", "true", "y", "yes"]:
|
||||
lightweight_mode = True
|
||||
elif lightweight_signal 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" %}')
|
||||
|
||||
Reference in New Issue
Block a user