feat: move fonts to public folder to fetch only when necessary
This commit is contained in:
parent
eda7873ec7
commit
52015aaf3f
367 changed files with 15 additions and 2 deletions
.vitepress/theme
public/fonts
1Row.flf3-D.flf3D Diagonal.flf3D-ASCII.flf3d.flf3d_diagonal.flf3x5.flf4Max.flf5 Line Oblique.flf5lineoblique.flfAMC 3 Line.flfAMC 3 Liv1.flfAMC AAA01.flfAMC Neko.flfAMC Razor.flfAMC Razor2.flfAMC Slash.flfAMC Slider.flfAMC Thin.flfAMC Tubes.flfAMC Untitled.flfANSI Regular.flfANSI Shadow.flfASCII New Roman.flfAcrobatic.flfAlligator.flfAlligator2.flfAlpha.flfAlphabet.flfArrows.flfAvatar.flfB1FF.flfBanner.flfBanner3-D.flfBanner3.flfBanner4.flfBarbwire.flfBasic.flfBear.flfBell.flfBenjamin.flfBig Chief.flfBig Money-ne.flfBig Money-nw.flfBig Money-se.flfBig Money-sw.flfBig.flfBigfig.flfBinary.flfBlock.flfBlocks.flfBloody.flfBolger.flfBraced.flfBright.flfBroadway KB.flfBroadway.flfBubble.flfBulbhead.flfCaligraphy.flfCaligraphy2.flfCalvin S.flfCards.flfCatwalk.flfChiseled.flfChunky.flfCoinstak.flfCola.flfColossal.flfComputer.flfContessa.flfContrast.flfCosmike.flfCrawford.flfCrawford2.flfCrazy.flfCricket.flfCursive.flfCyberlarge.flfCybermedium.flfCybersmall.flfCygnet.flfDANC4.flfDOS Rebel.flfDWhistled.flfDancing Font.flfDecimal.flfDef Leppard.flfDelta Corps Priest 1.flfDiamond.flfDiet Cola.flfDigital.flfDoh.flfDoom.flfDot Matrix.flfDouble Shorts.flfDouble.flfDr Pepper.flfEfti Chess.flf
|
@ -1,9 +1,22 @@
|
||||||
import { FLFParser, FontLayoutManager } from '@figlet-ts/lib'
|
import { FLFParser, FontLayoutManager } from '@figlet-ts/lib'
|
||||||
|
|
||||||
|
const fontCache: Record<string, string> = {}
|
||||||
|
|
||||||
async function loadFont(name: 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 {
|
try {
|
||||||
const font = await import(`./fonts/${name}.flf?raw`)
|
const response = await fetch(`/fonts/${name}.flf`)
|
||||||
return font.default
|
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) {
|
} catch (e) {
|
||||||
console.error('Cannot load font', name, 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…
Add table
Reference in a new issue