Skip to content

Commit 673feb4

Browse files
hannahblairgradio-pr-botfreddyaboulton
authored
Fix website local font paths and font-weight CSS (#12966)
* fix font weight * fix font path for website * add changeset * add changeset * update stale theme.css --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Freddy Boulton <41651716+freddyaboulton@users.noreply.github.com>
1 parent 0595d1b commit 673feb4

File tree

7 files changed

+22
-9
lines changed

7 files changed

+22
-9
lines changed

.changeset/nine-towns-smoke.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"gradio": patch
3+
"website": patch
4+
---
5+
6+
fix:Fix website local font paths and font-weight CSS

gradio/themes/utils/fonts.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,22 @@ def stylesheet(self) -> dict:
8686
css_template = textwrap.dedent("""
8787
@font-face {{
8888
font-family: '{name}';
89-
src: url('static/fonts/{file_name}/{file_name}-{weight}.woff2') format('woff2');
90-
font-weight: {weight};
89+
src: url('static/fonts/{file_name}/{file_name}-{file_weight}.woff2') format('woff2');
90+
font-weight: {css_weight};
9191
font-style: normal;
9292
}}
9393
""")
9494
css_rules = []
9595
for weight in self.weights:
96-
weight_name = (
96+
file_weight = (
9797
"Regular" if weight == 400 else "Bold" if weight == 700 else str(weight)
9898
)
9999
css_rules.append(
100100
css_template.format(
101101
name=self.name,
102102
file_name=self.name.replace(" ", ""),
103-
weight=weight_name,
103+
file_weight=file_weight,
104+
css_weight=weight,
104105
)
105106
)
106107
return {"url": None, "css": "\n".join(css_rules)}

js/_website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.71.1",
44
"private": true,
55
"scripts": {
6-
"dev": "pip install boto3 markdown && python generate_jsons/generate.py && python ../../scripts/generate_theme.py --outfile ./src/lib/assets/theme.css && vite dev",
6+
"dev": "pip install boto3 markdown && python generate_jsons/generate.py && python ../../scripts/generate_theme.py --website --outfile ./src/lib/assets/theme.css && vite dev",
77
"build": "vite build",
88
"preview": "vite preview",
99
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",

js/_website/src/lib/assets/theme.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
@font-face {
22
font-family: "IBM Plex Mono";
3-
src: url("static/fonts/IBMPlexMono/IBMPlexMono-Regular.woff2") format("woff2");
4-
font-weight: Regular;
3+
src: url("/fonts/IBMPlexMono/IBMPlexMono-Regular.woff2") format("woff2");
4+
font-weight: 400;
55
font-style: normal;
66
}
77

88
@font-face {
99
font-family: "IBM Plex Mono";
10-
src: url("static/fonts/IBMPlexMono/IBMPlexMono-Bold.woff2") format("woff2");
11-
font-weight: Bold;
10+
src: url("/fonts/IBMPlexMono/IBMPlexMono-Bold.woff2") format("woff2");
11+
font-weight: 700;
1212
font-style: normal;
1313
}
1414

36 KB
Binary file not shown.
34.7 KB
Binary file not shown.

scripts/generate_theme.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@
1111
parser.add_argument(
1212
"--theme", choices=["default", "glass", "monochrome", "soft"], default="default"
1313
)
14+
parser.add_argument(
15+
"--website", action="store_true", help="Adjust paths for SvelteKit website"
16+
)
1417
args = parser.parse_args()
1518

1619
ThemeClass = getattr(themes, args.theme.capitalize())
1720
css = ThemeClass()._get_theme_css()
1821

22+
if args.website:
23+
css = css.replace("url('static/", "url('/")
24+
1925
args.outfile.write(css)

0 commit comments

Comments
 (0)