Skip to content

Commit

Permalink
fix(preset-web-fonts): fix creation of import URL for bunny (#2766)
Browse files Browse the repository at this point in the history
  • Loading branch information
arunanshub committed Jun 26, 2023
1 parent 077b942 commit 3c28607
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions packages/preset-web-fonts/src/providers/bunny.ts
@@ -1,3 +1,33 @@
import { createGoogleCompatibleProvider } from './google'
import type { Provider, WebFontsProviders } from '../types'

export const BunnyFontsProvider = createGoogleCompatibleProvider('bunny', 'https://fonts.bunny.net')
export function createBunnyFontsProvider(
name: WebFontsProviders,
host: string,
): Provider {
return {
name,
getImportUrl(fonts): string {
const fontFamilies = fonts.map((font) => {
const { name, weights, italic } = font
const formattedName = name.toLowerCase().replace(/\s/g, '-')
if (!weights?.length) {

Check failure on line 13 in packages/preset-web-fonts/src/providers/bunny.ts

View workflow job for this annotation

GitHub Actions / lint

Unnecessary { after 'if' condition
return `${formattedName}${italic ? ':i' : ''}`
}
let weightsAsString = weights.sort().map(weight => weight.toString())
// 1. if weights have at least one element that has 'i', ignore the `italic` flag.
// 2. if none of the weights have an 'i' and italic is true, append an 'i'
const weightsHaveItalic = weightsAsString.some(weight => weight.endsWith('i'))
if (!weightsHaveItalic && italic)
weightsAsString = weightsAsString.map(weight => weight += 'i')

return `${formattedName}:${weightsAsString.join(',')}`
})
return `${host}/css?family=${fontFamilies.join('|')}`
},
}
}

export const BunnyFontsProvider: Provider = createBunnyFontsProvider(
'bunny',
'https://fonts.bunny.net',
)

0 comments on commit 3c28607

Please sign in to comment.