Skip to content

feat: allow passing range for custom font-weight #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/vitepress/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vitepress",
"private": true,
"type": "module",
"private": true,
"scripts": {
"dev": "vitepress dev",
"start": "vitepress dev",
Expand Down
21 changes: 12 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -91,10 +90,11 @@ export default createUnplugin<Options | undefined>((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',
Expand All @@ -113,7 +113,8 @@ export default createUnplugin<Options | undefined>((userOptions) => {
const newTags = options?.custom?.linkFilter(tags)
if (Array.isArray(newTags)) {
tagsReturned = newTags
} else {
}
else {
tagsReturned = newTags ? tags : []
}
}
Expand All @@ -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({
Expand All @@ -164,7 +166,8 @@ function generateVitepressBundle(
const newTags = options?.custom?.linkFilter(tags)
if (Array.isArray(newTags)) {
tagsReturned = newTags
} else {
}
else {
tagsReturned = newTags ? tags : []
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HtmlTagDescriptor } from "vite"
import type { HtmlTagDescriptor } from 'vite'

export interface Options {
custom?: CustomFonts
Expand All @@ -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[]
Expand Down