Skip to content
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

feat: warn when font weights are not available #35

Merged
merged 5 commits into from
Mar 9, 2024
Merged

feat: warn when font weights are not available #35

merged 5 commits into from
Mar 9, 2024

Conversation

qwerzl
Copy link
Collaborator

@qwerzl qwerzl commented Mar 6, 2024

This pull request warns users when some of the font weights are not available, or throws an error when none of the font weights are available (as the latter situation causes a 400 error with an empty array).

@danielroe
Copy link
Member

Nice idea! Do you have an example of a setup that would trigger this?

@qwerzl
Copy link
Collaborator Author

qwerzl commented Mar 7, 2024

@danielroe Sure. If you add weights: [500, 700] to the config in playground, it would be triggered.

CleanShot 2024-03-08 at 07 32 53@2x

Total config is as belows:

export default defineNuxtConfig({
  modules: ['@nuxt/fonts', '@nuxtjs/tailwindcss', '@unocss/nuxt'],
  unocss: {
    disableNuxtInlineStyle: false,
  },
  fonts: {
    providers: {
      custom: '~/providers/custom'
    },
    families: [
      { name: 'Abel', provider: 'bunny' },
      { name: 'Satoshi', provider: 'fontshare' },
      { name: 'Kode Mono', provider: 'none' },
      { name: 'MyCustom', src: '/custom-font.woff2' },
      { name: 'CustomGlobal', global: true, src: '/font-global.woff2' },
      { name: 'Oswald', fallbacks: ['Times New Roman'] },
    ],
    defaults: {
      weights: [500, 700],
      fallbacks: {
        monospace: ['Tahoma']
      }
    }
  },
})

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this!

Let's go ahead without logging errors but moving on to the next provider and warning if a custom configuration has produced the error. It's tricky to know how verbose to be when logging missing fonts but this is something we can iterate on.

@danielroe danielroe merged commit 5a4c37a into nuxt:main Mar 9, 2024
1 check passed
@github-actions github-actions bot mentioned this pull request Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants