Skip to content

Commit f3a74e8

Browse files
authored
Update shell.handlebars - local font support
This template checks if the font variable starts with a slash and, if so, declares a custom font using @font-face with the name LocalFont. If the font URL does not start with a slash, it assumes it is a Google Fonts URL.
1 parent 2974f47 commit f3a74e8

File tree

1 file changed

+16
-41
lines changed

1 file changed

+16
-41
lines changed

sqlpage/templates/shell.handlebars

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,25 @@
1616
{{/if}}
1717
{{/each}}
1818

19-
{{!-- Ensure font is an array --}}
2019
{{#if font}}
21-
{{#if (not (isArray font))}}
22-
{{!-- Wrap single font string in an array --}}
23-
{{#set "font" (array font)}}
24-
{{/if}}
25-
{{/if}}
26-
27-
{{#if font}}
28-
<style>
29-
{{#each font}}
30-
{{#if (startsWith this "/")}}
31-
@font-face {
32-
font-family: '{{this}}_custom';
33-
src: url('{{this}}.woff2') format('woff2'),
34-
url('{{this}}.woff') format('woff'),
35-
url('{{this}}.ttf') format('truetype'),
36-
url('{{this}}.otf') format('opentype'),
37-
url('{{this}}.eot') format('embedded-opentype'),
38-
url('{{this}}.svg#{{this}}_custom') format('svg');
39-
}
40-
{{/if}}
41-
{{/each}}
42-
</style>
43-
44-
{{!-- Handling Google Fonts --}}
45-
{{#each (filter font (lambda font (not (startsWith font "/"))))}}
20+
{{#if (startsWith font "/")}}
21+
<style>
22+
@font-face {
23+
font-family: 'LocalFont';
24+
src: url('{{font}}') format('woff2');
25+
font-weight: normal;
26+
font-style: normal;
27+
}
28+
:root {
29+
--tblr-font-sans-serif: 'LocalFont', Arial, sans-serif;
30+
}
31+
</style>
32+
{{else}}
4633
<link rel="preconnect" href="https://fonts.googleapis.com">
4734
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
48-
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family={{this}}&display=fallback">
49-
{{/each}}
50-
51-
<style>
52-
:root {
53-
{{#each font}}
54-
{{!-- Local fonts will have _custom appended to their names --}}
55-
{{#if (startsWith this "/")}}
56-
--tblr-font-{{replace this "/" "-"}}: '{{this}}_custom', Arial, sans;
57-
{{else}}
58-
--tblr-font-{{replace this " " "-"}}: '{{this}}', Arial, sans;
59-
{{/if}}
60-
{{/each}}
61-
}
62-
</style>
35+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family={{font}}&display=fallback">
36+
<style>:root { --tblr-font-sans-serif: '{{font}}', Arial, sans-serif;}</style>
37+
{{/if}}
6338
{{/if}}
6439

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

0 commit comments

Comments
 (0)