Skip to content

Commit 8d8d48d

Browse files
committed
fix: resolve fontname.ttf template asset resolution warnings
- Move font style template from <style> to <script type='text/template'> - This prevents Vite from processing CSS content and trying to resolve font URLs - Template is still used by JavaScript to dynamically generate font styles - Fixes 'fontname.ttf didn't resolve at build time' warnings - Maintains existing functionality for dynamic font switching
1 parent 5119bda commit 8d8d48d

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/components/ContentWrap.jsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,19 @@ export default class ContentWrap extends Component {
445445
// Replace correct css file in LINK tags's href
446446
window.editorThemeLinkTag.href = `lib/codemirror/theme/${prefs.editorTheme}.css`;
447447
window.fontStyleTag.textContent =
448-
window.fontStyleTemplate.textContent.replace(
449-
/fontname/g,
450-
(prefs.editorFont === 'other'
451-
? prefs.editorCustomFont
452-
: prefs.editorFont) || 'FiraCode',
453-
);
448+
window.fontStyleTemplate.textContent
449+
.replace(
450+
/fontname/g,
451+
(prefs.editorFont === 'other'
452+
? prefs.editorCustomFont
453+
: prefs.editorFont) || 'FiraCode',
454+
)
455+
.replace(
456+
/__FONTNAME__/g,
457+
'/' + ((prefs.editorFont === 'other'
458+
? prefs.editorCustomFont
459+
: prefs.editorFont) || 'FiraCode'),
460+
);
454461
// window.customEditorFontInput.classList[
455462
// prefs.editorFont === 'other' ? 'remove' : 'add'
456463
// ]('hide');

src/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
<link rel="stylesheet" href="/style.css" />
6969

70-
<style id="fontStyleTemplate" type="template">
70+
<script id="fontStyleTemplate" type="text/template">
7171
@font-face {
7272
font-family: 'fontname';
7373
font-style: normal;
@@ -80,7 +80,7 @@
8080
.CodeMirror pre {
8181
font-family: 'fontname', monospace;
8282
}
83-
</style>
83+
</script>
8484
<style type="text/css" id="fontStyleTag">
8585
@font-face {
8686
font-family: 'FiraCode';

0 commit comments

Comments
 (0)