feat: move fonts to public folder to fetch only when necessary
This commit is contained in:
parent
e09bbf6cdf
commit
852c38f41e
367 changed files with 15 additions and 2 deletions
|
@ -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…
Reference in a new issue