From b087d47ec514f72820109cfdb0bf833480fde7d7 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 23 Sep 2024 13:02:47 +0100 Subject: [PATCH] fix(local): use `extname` for extension priority test resolves https://github.com/nuxt/fonts/issues/135 resolves https://github.com/nuxt/fonts/issues/223 --- src/providers/local.ts | 8 ++++---- test/providers/local.test.ts | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/providers/local.ts b/src/providers/local.ts index 03ef9fb..4095444 100644 --- a/src/providers/local.ts +++ b/src/providers/local.ts @@ -1,5 +1,5 @@ import { glob } from 'tinyglobby' -import { join, relative, resolve } from 'pathe' +import { join, extname, relative, resolve } from 'pathe' import { filename } from 'pathe/utils' import { anyOf, createRegExp, not, wordBoundary } from 'magic-regexp' @@ -147,7 +147,7 @@ function unregisterFont(path: string) { } } -const extensionPriority = ['woff2', 'woff', 'ttf', 'otf', 'eot'] +const extensionPriority = ['.woff2', '.woff', '.ttf', '.otf', '.eot'] function lookupFont(family: string, suffixes: Array): string[] { const slug = [fontFamilyToSlug(family), ...suffixes].join('-') const paths = providerContext.registry[slug] @@ -162,8 +162,8 @@ function lookupFont(family: string, suffixes: Array): string[] } return [...fonts].sort((a, b) => { - const extA = filename(a).split('.').pop()! - const extB = filename(b).split('.').pop()! + const extA = extname(a) + const extB = extname(b) return extensionPriority.indexOf(extA) - extensionPriority.indexOf(extB) }) diff --git a/test/providers/local.test.ts b/test/providers/local.test.ts index 04e7909..4ea095b 100644 --- a/test/providers/local.test.ts +++ b/test/providers/local.test.ts @@ -30,11 +30,11 @@ describe('local font provider', () => { "fonts": [ { "src": [ - "/font.eot", - "/font.otf", - "/font.ttf", - "/font.woff", "/font.woff2", + "/font.woff", + "/font.ttf", + "/font.otf", + "/font.eot", ], "style": "normal", "weight": "normal", @@ -83,10 +83,10 @@ describe('local font provider', () => { [ { "src": [ - "/MyFont.700.eot", "/MyFont_bold.woff2", - "/MyFontbold-latin.ttf", "/MyFontbold-latin.woff", + "/MyFontbold-latin.ttf", + "/MyFont.700.eot", ], "style": "normal", "weight": "bold",