Skip to content

Commit 15b3766

Browse files
authored
Update shell.handlebars - multiple fonts + local
Explanation of Changes Handling Multiple Fonts: The font_custom variable is treated as an array, and for each font, a @font-face rule is generated if the font URL starts with / (indicating a local font). The CSS variables are dynamically named using the font name, replacing spaces and slashes to ensure valid CSS variable names. Google Fonts: Google Fonts are handled by filtering the font_custom array to include only those fonts that do not start with /. Multiple Google Fonts are included by iterating over this filtered list and generating the necessary <link> tags. CSS Variables: CSS variables are created for each font in the :root selector. Local fonts will have _custom appended to their names to avoid conflicts with Google Fonts. This setup enables the registration and usage of multiple fonts, both locally stored and from Google Fonts, ensuring broad compatibility and flexibility for the user.
1 parent c0efd14 commit 15b3766

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

sqlpage/templates/shell.handlebars

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,48 @@
1010
<link rel="manifest" href="{{manifest}}">
1111
{{/if}}
1212
<link rel="stylesheet" href="{{static_path 'sqlpage.css'}}">
13-
{{#each (to_array css)}}
13+
{{#each (to_array css)}}
1414
{{#if this}}
1515
<link rel="stylesheet" href="{{this}}">
1616
{{/if}}
17-
{{/each}}
17+
{{/each}}
18+
19+
{{#if font_custom}}
20+
<style>
21+
{{#each font_custom}}
22+
{{#if (startsWith this "/")}}
23+
@font-face {
24+
font-family: '{{this}}_custom';
25+
src: url('{{this}}.woff2') format('woff2'),
26+
url('{{this}}.woff') format('woff'),
27+
url('{{this}}.ttf') format('truetype'),
28+
url('{{this}}.otf') format('opentype'),
29+
url('{{this}}.eot') format('embedded-opentype'),
30+
url('{{this}}.svg#{{this}}_custom') format('svg');
31+
}
32+
{{/if}}
33+
{{/each}}
34+
</style>
35+
36+
{{!-- Handling Google Fonts --}}
37+
{{#each (filter font_custom (lambda font (not (startsWith font "/"))))}}
38+
<link rel="preconnect" href="https://fonts.googleapis.com">
39+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
40+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family={{this}}&display=fallback">
41+
{{/each}}
1842

19-
{{#if font}}
20-
<link rel="preconnect" href="https://fonts.googleapis.com">
21-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
22-
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family={{font}}&display=fallback">
23-
<style>:root { --tblr-font-sans-serif: '{{font}}', Arial, sans;}</style>
43+
<style>
44+
:root {
45+
{{#each font_custom}}
46+
{{!-- Local fonts will have _custom appended to their names --}}
47+
{{#if (startsWith this "/")}}
48+
--tblr-font-{{replace this "/" "-"}}: '{{this}}_custom', Arial, sans;
49+
{{else}}
50+
--tblr-font-{{replace this " " "-"}}: '{{this}}', Arial, sans;
51+
{{/if}}
52+
{{/each}}
53+
}
54+
</style>
2455
{{/if}}
2556

2657
<script src="{{static_path 'sqlpage.js'}}" defer></script>

0 commit comments

Comments
 (0)