-
Notifications
You must be signed in to change notification settings - Fork 33
Fonts #1039
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
base: main
Are you sure you want to change the base?
Fonts #1039
Conversation
|
How does preloading pick the What's the reasoning behind considering subsetting a non-goal? It helps a lot when the font participates in LCP and is trivial to do when using google fonts directly. Moving to astro fonts in that case would be a downgrade. |
I think we can't choose the src to pick automatically, so that would preload everything? Not sure, have ideas in mind?
Only automatic subsetting is a non goal (eg. by analyzing the static content), subsetting is actually supported. I'll clarify the non goal |
|
Thanks for the feedback!
This should not be the case. It was fixed recently, did you try with the latest version of Astro?
That's a good point. I quite like what you're suggesting but that would only work for the local provider. I wonder if there's a way to support it for remote providers, or to move it somewhere else? eg. ---
import { Font } from 'astro:assets';
---
<Font cssVariable="--font-custom" preload={[400,500]} />It's less centralized but it works for all kinds of providers |
Big fan of this |
Yeah, I am on As you can see this code block is in the But there is no equivalent logic for the
This looks like a pretty good solution! The only question is if it should be differentiated between different So, together, the type for the type FontProps = {
// ...
preload: (number | string | { weight: number | string, style: 'normal' | 'italic' | 'oblique' })[]
// ...
};Which, once implemented, would make it pretty flexible: ---
import { Font } from 'astro:assets';
---
<Font cssVariable="--font-custom" preload={[ 400, { weight: 500, style: 'normal' } ]} />Just my suggestion! |
You're right! I have a fix on another branch so that should land soon-ish |
|
Hello, I did run into an issue when trying to use fonts from Fontshare. There's an issue with the URL for the Fontshare CDN (it looks malformed in the error message), as it's consistently throwing an error when trying to load a font. You can see the error in the screenshot below:
Minimal reproduction: https://congenial-couscous-4jpj9qg4gp42jv6v.github.dev/ |
|
Hi, thanks for trying it out! Can you open an issue at https://github.com/withastro/astro/issues instead? Thanks! |
|
If you are using the local provider, I'd like your feedback on withastro/astro#13640! |
|
I have the same request as @tanishqmanuja, my use case is to generate OG images with Satori What I usually do is to read the const fontData = fs.readFileSync(
'node_modules/@fontsource/ia-writer-duo/files/ia-writer-duo-latin-400-normal.woff'
)and then integrate it in Satori like this const raw = await satori(htmlContent as React.ReactNode, {
width,
height,
fonts: [
{
name: 'IA Writer Duo',
data: fontData,
style: 'normal',
weight: 400
}
]
})I would appreciate a way to achieve this with this feature and thus not depend on extra installations (as in this case manually install a font from fontsource) Thanks 🙌 |
|
I plan to look into this in the next 2 weeks! |
|
Hi there! I'm working on a way to retrieve URLs, give it a try and share your experience on the PR: withastro/astro#13811 |
cc @tanishqmanuja and @Pkcarreno |
|
Hi there! I'm working on a way to have more granular preloads, give it a try and share your experience on the PR: withastro/astro#13826 cc @jonasgeiler |
|
I think in builds we should keep them as is as it's better for caching but in dev, we could either do something like |
|
Agreed with the dev/build I'm fine with either naming convention, the hashes being there doesn't bother me as long as the name is there too 👍 |
Perhaps after what we learned in #13826 it might also be good to indicate if the file is a subset as well? (if possible) 😅 |
|
The experimental Fonts API inserts elements at the beginning of the |
IIUC the |
|
Yes as Chris said you control the position in the head |
|
What do you think about {
- cssVariable: '--my-font'
+ cssVariable: 'my-font'
}
-<Font cssVariable="--my-font" />
+<Font cssVariable="my-font" />:root {
font-family: var(--my-font);
} |
Personally, I don't mind either way, but for consistency, I think it would be nice to require the |
|
Agreed on requiring the |


Summary
Have first-party support for fonts in Astro:
Links