Skip to content

Commit

Permalink
fix(local): use extname for extension priority test
Browse files Browse the repository at this point in the history
resolves #135
resolves #223
  • Loading branch information
danielroe committed Sep 23, 2024
1 parent fa35a69 commit b087d47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/providers/local.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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 | number>): string[] {
const slug = [fontFamilyToSlug(family), ...suffixes].join('-')
const paths = providerContext.registry[slug]
Expand All @@ -162,8 +162,8 @@ function lookupFont(family: string, suffixes: Array<string | number>): 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)
})
Expand Down
12 changes: 6 additions & 6 deletions test/providers/local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit b087d47

Please sign in to comment.