From a73895c39480566eff1d5b82a35ef107cf9b0343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vojt=C3=A1=C5=A1ek?= Date: Fri, 20 Dec 2024 10:51:27 +0100 Subject: [PATCH 1/2] fix: fixed eslint errors --- examples/vitepress/package.json | 2 +- src/index.ts | 21 ++++++++++++--------- src/types.ts | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/vitepress/package.json b/examples/vitepress/package.json index d2a0b2d..7e78524 100644 --- a/examples/vitepress/package.json +++ b/examples/vitepress/package.json @@ -1,7 +1,7 @@ { "name": "vitepress", - "private": true, "type": "module", + "private": true, "scripts": { "dev": "vitepress dev", "start": "vitepress dev", diff --git a/src/index.ts b/src/index.ts index 47d7c17..80a8103 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,6 @@ import { createUnplugin } from 'unplugin' import { getHeadLinkTags } from './loaders' import { customVirtualModule } from './loaders/custom' import { fontsourceImports, fontsourceVirtualModule } from './loaders/fontsource' -import { HtmlTagDescriptor } from 'vite' const virtualStylesId = 'unfonts.css' const resolvedVirtualStylesId = `\0${virtualStylesId}` @@ -91,10 +90,11 @@ export default createUnplugin((userOptions) => { const { prefetch: wantPrefetch, preload: wantPreload } = options?.custom || {} for (const file of files) { if (!( - wantPrefetch === true || wantPreload === true || - (wantPrefetch === undefined && wantPreload === undefined) - )) + wantPrefetch === true || wantPreload === true + || (wantPrefetch === undefined && wantPreload === undefined) + )) { continue + } const ext = extname(file) tags.push({ tag: 'link', @@ -113,7 +113,8 @@ export default createUnplugin((userOptions) => { const newTags = options?.custom?.linkFilter(tags) if (Array.isArray(newTags)) { tagsReturned = newTags - } else { + } + else { tagsReturned = newTags ? tags : [] } } @@ -140,10 +141,11 @@ function generateVitepressBundle( const { prefetch: wantPrefetch, preload: wantPreload } = options?.custom || {} for (const file of files) { if (!( - wantPrefetch === true || wantPreload === true || - (wantPrefetch === undefined && wantPreload === undefined) - )) + wantPrefetch === true || wantPreload === true + || (wantPrefetch === undefined && wantPreload === undefined) + )) { continue + } const ext = extname(file) tags.push({ @@ -164,7 +166,8 @@ function generateVitepressBundle( const newTags = options?.custom?.linkFilter(tags) if (Array.isArray(newTags)) { tagsReturned = newTags - } else { + } + else { tagsReturned = newTags ? tags : [] } } diff --git a/src/types.ts b/src/types.ts index c983972..ce00a8e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import { HtmlTagDescriptor } from "vite" +import type { HtmlTagDescriptor } from 'vite' export interface Options { custom?: CustomFonts From ee0c9e59f09b68de2a4e04ea7ba1b185df312ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vojt=C3=A1=C5=A1ek?= Date: Fri, 20 Dec 2024 10:52:54 +0100 Subject: [PATCH 2/2] feat: allow passing range for custom font-weight --- src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index ce00a8e..ad268c4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -12,7 +12,7 @@ export interface CustomFontFace { source: string name: string basename: string - weight: number + weight: number | `${number} ${number}` style: string display: string local?: string | string[]