Skip to content

Commit

Permalink
better theme
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-husky committed Jan 21, 2024
1 parent b55d573 commit d818c38
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 66 deletions.
21 changes: 21 additions & 0 deletions themes/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from toolbox import get_conf
CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf("CODE_HIGHLIGHT", "ADD_WAIFU", "LAYOUT")

def get_common_html_javascript_code():
js = "\n"
for jsf in [
"file=themes/common.js",
"file=themes/mermaid.min.js",
"file=themes/mermaid_loader.js",
]:
js += f"""<script src="{jsf}"></script>\n"""

# 添加Live2D
if ADD_WAIFU:
for jsf in [
"file=docs/waifu_plugin/jquery.min.js",
"file=docs/waifu_plugin/jquery-ui.min.js",
"file=docs/waifu_plugin/autoload.js",
]:
js += f"""<script src="{jsf}"></script>\n"""
return js
19 changes: 3 additions & 16 deletions themes/contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,9 @@ def adjust_theme():
button_cancel_text_color_dark="white",
)

js = ""
for jsf in [
os.path.join(theme_dir, "common.js"),
os.path.join(theme_dir, "mermaid.min.js"),
os.path.join(theme_dir, "mermaid_loader.js"),
]:
with open(jsf, "r", encoding="utf8") as f:
js += f"<script>{f.read()}</script>"

# 添加一个萌萌的看板娘
if ADD_WAIFU:
js += """
<script src="file=docs/waifu_plugin/jquery.min.js"></script>
<script src="file=docs/waifu_plugin/jquery-ui.min.js"></script>
<script src="file=docs/waifu_plugin/autoload.js"></script>
"""
from themes.common import get_common_html_javascript_code
js = get_common_html_javascript_code()

if not hasattr(gr, "RawTemplateResponse"):
gr.RawTemplateResponse = gr.routes.templates.TemplateResponse
gradio_original_template_fn = gr.RawTemplateResponse
Expand Down
18 changes: 2 additions & 16 deletions themes/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,8 @@ def adjust_theme():
button_cancel_text_color_dark="white",
)

js = ""
for jsf in [
os.path.join(theme_dir, "common.js"),
os.path.join(theme_dir, "mermaid.min.js"),
os.path.join(theme_dir, "mermaid_loader.js"),
]:
with open(jsf, "r", encoding="utf8") as f:
js += f"<script>{f.read()}</script>"

# 添加一个萌萌的看板娘
if ADD_WAIFU:
js += """
<script src="file=docs/waifu_plugin/jquery.min.js"></script>
<script src="file=docs/waifu_plugin/jquery-ui.min.js"></script>
<script src="file=docs/waifu_plugin/autoload.js"></script>
"""
from themes.common import get_common_html_javascript_code
js = get_common_html_javascript_code()
if not hasattr(gr, "RawTemplateResponse"):
gr.RawTemplateResponse = gr.routes.templates.TemplateResponse
gradio_original_template_fn = gr.RawTemplateResponse
Expand Down
20 changes: 3 additions & 17 deletions themes/gradios.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,9 @@ def adjust_theme():
THEME = THEME.lstrip("huggingface-")
set_theme = set_theme.from_hub(THEME.lower())

js = ""
for jsf in [
os.path.join(theme_dir, "common.js"),
os.path.join(theme_dir, "mermaid.min.js"),
os.path.join(theme_dir, "mermaid_loader.js"),
]:
with open(jsf, "r", encoding="utf8") as f:
js += f"<script>{f.read()}</script>"


# 添加一个萌萌的看板娘
if ADD_WAIFU:
js += """
<script src="file=docs/waifu_plugin/jquery.min.js"></script>
<script src="file=docs/waifu_plugin/jquery-ui.min.js"></script>
<script src="file=docs/waifu_plugin/autoload.js"></script>
"""
from themes.common import get_common_html_javascript_code
js = get_common_html_javascript_code()

if not hasattr(gr, "RawTemplateResponse"):
gr.RawTemplateResponse = gr.routes.templates.TemplateResponse
gradio_original_template_fn = gr.RawTemplateResponse
Expand Down
18 changes: 2 additions & 16 deletions themes/green.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,8 @@ def adjust_theme():
chatbot_code_background_color_dark="*neutral_950",
)

js = ""
for jsf in [
os.path.join(theme_dir, "common.js"),
os.path.join(theme_dir, "mermaid.min.js"),
os.path.join(theme_dir, "mermaid_loader.js"),
]:
with open(jsf, "r", encoding="utf8") as f:
js += f"<script>{f.read()}</script>"

# 添加一个萌萌的看板娘
if ADD_WAIFU:
js += """
<script src="file=docs/waifu_plugin/jquery.min.js"></script>
<script src="file=docs/waifu_plugin/jquery-ui.min.js"></script>
<script src="file=docs/waifu_plugin/autoload.js"></script>
"""
from themes.common import get_common_html_javascript_code
js = get_common_html_javascript_code()

with open(os.path.join(theme_dir, "green.js"), "r", encoding="utf8") as f:
js += f"<script>{f.read()}</script>"
Expand Down
2 changes: 1 addition & 1 deletion themes/mermaid_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const uml = async className => {
defaultConfig.theme = "dark"
}

const Module = await import('./file=themes/mermaid_editor.js');
const Module = await import('/file=themes/mermaid_editor.js');

function do_render(block, code, codeContent, cnt) {
var rendered_content = mermaid.render(`_diagram_${cnt}`, code);
Expand Down

0 comments on commit d818c38

Please sign in to comment.