mirror of https://github.com/tiangolo/fastapi.git
✨ Allow disabling Google fonts in ReDoc (#481)
This commit is contained in:
parent
5b3df28f0c
commit
c90c4fb6c1
|
|
@ -56,6 +56,7 @@ def get_redoc_html(
|
||||||
title: str,
|
title: str,
|
||||||
redoc_js_url: str = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js",
|
redoc_js_url: str = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js",
|
||||||
redoc_favicon_url: str = "https://fastapi.tiangolo.com/img/favicon.png",
|
redoc_favicon_url: str = "https://fastapi.tiangolo.com/img/favicon.png",
|
||||||
|
with_google_fonts: bool = True,
|
||||||
) -> HTMLResponse:
|
) -> HTMLResponse:
|
||||||
html = f"""
|
html = f"""
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
@ -65,7 +66,12 @@ def get_redoc_html(
|
||||||
<!-- needed for adaptive design -->
|
<!-- needed for adaptive design -->
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
"""
|
||||||
|
if with_google_fonts:
|
||||||
|
html += """
|
||||||
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
|
||||||
|
"""
|
||||||
|
html += f"""
|
||||||
<link rel="shortcut icon" href="{redoc_favicon_url}">
|
<link rel="shortcut icon" href="{redoc_favicon_url}">
|
||||||
<!--
|
<!--
|
||||||
ReDoc doesn't change outer page styles
|
ReDoc doesn't change outer page styles
|
||||||
|
|
|
||||||
|
|
@ -54,3 +54,14 @@ def test_strings_in_custom_redoc():
|
||||||
body_content = html.body.decode()
|
body_content = html.body.decode()
|
||||||
assert redoc_js_url in body_content
|
assert redoc_js_url in body_content
|
||||||
assert redoc_favicon_url in body_content
|
assert redoc_favicon_url in body_content
|
||||||
|
|
||||||
|
|
||||||
|
def test_google_fonts_in_generated_redoc():
|
||||||
|
body_with_google_fonts = get_redoc_html(
|
||||||
|
openapi_url="/docs", title="title"
|
||||||
|
).body.decode()
|
||||||
|
assert "fonts.googleapis.com" in body_with_google_fonts
|
||||||
|
body_without_google_fonts = get_redoc_html(
|
||||||
|
openapi_url="/docs", title="title", with_google_fonts=False
|
||||||
|
).body.decode()
|
||||||
|
assert "fonts.googleapis.com" not in body_without_google_fonts
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue