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

fix(preset-web-fonts): sort weights as string using localeCompare #2845

Merged
merged 9 commits into from Jul 15, 2023

Conversation

arunanshub
Copy link
Contributor

Previously, the weights were converted to Number before sorting. This would lead to conversion of string to NaN.

@arunanshub arunanshub requested a review from antfu as a code owner July 8, 2023 20:55
@netlify
Copy link

netlify bot commented Jul 8, 2023

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit b1e08fa
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/64b26be3481b1500082a3c84
😎 Deploy Preview https://deploy-preview-2845--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@zyyv zyyv enabled auto-merge (squash) July 15, 2023 07:23
@zyyv zyyv disabled auto-merge July 15, 2023 07:24
@zyyv
Copy link
Member

zyyv commented Jul 15, 2023

@arunanshub Is there any downside to using map(Number).sort((a,b)=>a-b), We are missing a step to judge whether it is a number.

@zyyv
Copy link
Member

zyyv commented Jul 15, 2023

@arunanshub I changed the code a bit, feel free to optimize it. By the way can you add a test case for bunny. Need your review.

@arunanshub
Copy link
Contributor Author

@zyyv In UnoCSS docs for Web fonts preset we should ideally be able to selectively choose the font weights along with their italicized versions. This is currently possible using this configuration:

{
  // ...
  fonts: {
    sans: 'Roboto',
    mono: ['Fira Mono:400,700i'],
  }
}

However, this method is sub-optimal. It is cleaner if we specify the weights like this:

{
  // ...
  fonts: {
    sans: 'Roboto',
    mono: {
      name: 'Fira Code',
      weights: [400, '700i'],
    },
  }
}

However, the current weight sorting function converts all the weight values to numbers, which converts the italicized weights to NaN.

@zyyv
Copy link
Member

zyyv commented Jul 15, 2023

I see, I will revert my changes. Thank you for your guide.

@arunanshub
Copy link
Contributor Author

@arunanshub I changed the code a bit, feel free to optimize it. By the way can you add a test case for bunny. Need your review.

@zyyv The removal of italicized font weights undermines the objectives of the pull request. Our intention is to sort all font weights, including the italicized versions.

@zyyv
Copy link
Member

zyyv commented Jul 15, 2023

I didn't know the weight would carry the italics, thanks again.

@zyyv zyyv enabled auto-merge (squash) July 15, 2023 09:52
@zyyv zyyv merged commit 1bfba0d into unocss:main Jul 15, 2023
10 checks passed
@arunanshub arunanshub deleted the weight-sort branch July 15, 2023 10:00
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