feat: move fonts to public folder to fetch only when necessary

Norman Köhring 5 months ago
parent eda7873ec7
commit 52015aaf3f

@ -1,9 +1,22 @@
import { FLFParser, FontLayoutManager } from '@figlet-ts/lib'
const fontCache: Record<string, string> = {}
async function loadFont(name: string) {
if (fontCache[name]) {
console.debug('getting font from cache:', name)
return fontCache[name]
}
console.debug('loading non-cached font:', name)
try {
const font = await import(`./fonts/${name}.flf?raw`)
return font.default
const response = await fetch(`/fonts/${name}.flf`)
if (response.ok) {
const font = await response.text()
fontCache[name] = font
return font
}
throw new Error(`Failed to load or parse font! Response is ${response.status} - ${response.statusText}`)
} catch (e) {
console.error('Cannot load font', name, e)
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save