-
Notifications
You must be signed in to change notification settings - Fork 6
-
Notifications
You must be signed in to change notification settings - Fork 6
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
cdnURL is not respected by google provider #224
Comments
To resolve the issue where Here's the modified async function resolveFontFaceWithOverride(fontFamily: string, override?: FontFamilyManualOverride | FontFamilyProviderOverride, fallbackOptions?: { fallbacks: string[], generic?: GenericCSSFamily }): Promise<FontFaceResolution | undefined> {
const fallbacks = override?.fallbacks || normalizedDefaults.fallbacks[fallbackOptions?.generic || 'sans-serif']
if (override && 'src' in override) {
const fonts = normalizeFontData({
src: override.src,
display: override.display,
weight: override.weight,
style: override.style,
})
exposeFont({
type: 'manual',
fontFamily,
fonts,
})
return {
fallbacks,
fonts,
}
}
// Respect fonts that should not be resolved through `@nuxt/fonts`
if (override?.provider === 'none') {
return
}
// Respect custom weights, styles and subsets options
const defaults = { ...normalizedDefaults, fallbacks }
for (const key of ['weights', 'styles', 'subsets'] as const) {
if (override?.[key]) {
defaults[key as 'weights'] = override[key]!.map(v => String(v))
}
}
// Handle explicit provider
if (override?.provider) {
if (override.provider in providers) {
const result = await providers[override.provider]!.resolveFontFaces!(fontFamily, defaults)
// Rewrite font source URLs to be proxied/local URLs
const fonts = normalizeFontData(result?.fonts || [])
if (!fonts.length || !result) {
logger.warn(`Could not produce font face declaration from \`${override.provider}\` for font family \`${fontFamily}\`.`)
return
}
exposeFont({
type: 'override',
fontFamily,
provider: override.provider,
fonts,
})
return {
fallbacks: result.fallbacks || defaults.fallbacks,
fonts,
}
}
// If not registered, log and fall back to default providers
logger.warn(`Unknown provider \`${override.provider}\` for font family \`${fontFamily}\`. Falling back to default providers.`)
}
for (const key of prioritisedProviders) {
const provider = providers[key]!
if (provider.resolveFontFaces) {
const result = await provider.resolveFontFaces(fontFamily, defaults)
if (result) {
// Rewrite font source URLs to be proxied/local URLs
const fonts = normalizeFontData(result.fonts)
if (fonts.length > 0) {
exposeFont({
type: 'auto',
fontFamily,
provider: key,
fonts,
})
// Prepend CDN URL to font requests
const cdnURL = process.env.CDN_URL || 'https://your-cdn-url.com';
fonts.forEach(font => {
font.src = font.src.map(src => {
if (src.url.startsWith('/')) {
src.url = `${cdnURL}${src.url}`;
}
return src;
});
});
return {
fallbacks: result.fallbacks || defaults.fallbacks,
fonts,
}
}
if (override) {
logger.warn(`Could not produce font face declaration for \`${fontFamily}\` with override.`)
}
}
}
}
} In this modification, the |
app.cdnURL
(as the issue suggests) does not seem to be respected by the google provider, giving me 404s in production due to the font requests not being prepended correctly. Curiously, fonts provided by the local provider seem to be working as intended. I have not tried other providers, but as they look quite similar, I would presume this would also effect the other remote providers.What makes it even more curious, is that if the fonts have already been cached (i.e. through a previous build), the paths are generated correctly (prefixed by
cdnURL
).EDIT: Ok, so the reason it works after the fonts have been cached is that the remote fonts are now picked up by the local provider (since they have been cached locally), and thus served correctly.
The text was updated successfully, but these errors were encountered: