Skip to content
Merged
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
17 changes: 10 additions & 7 deletions packages/gamut-styles/src/AssetProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { webFonts } from './remoteAssets/fonts';

/*
* Only preload woff2 fonts, since woff1 are only included as fallbacks.
*/
export const createFontLinks = () =>
webFonts.flatMap(({ filePath, extensions }) =>
extensions.map((ext) => (
webFonts
.filter((f) => f.extensions.includes('woff2'))
.map(({ filePath }) => (
<link
key={`${filePath}-${ext}`}
key={filePath}
rel="preload"
href={`${filePath}.${ext}`}
href={`${filePath}.woff2`}
crossOrigin="anonymous"
as="font"
type={`font/${ext}`}
type="font/woff2"
/>
))
);
));

export const AssetProvider = () => {
return <>{createFontLinks()}</>;
Expand Down
14 changes: 8 additions & 6 deletions packages/gamut-styles/src/remoteAssets/fonts.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
export const FONT_ASSET_PATH = `https://www.codecademy.com/gamut`;

// woff2 should precede woff so that browsers try woff2 first.

export const webFonts = [
{
filePath: `${FONT_ASSET_PATH}/apercu-regular-pro`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Apercu',
},
{
filePath: `${FONT_ASSET_PATH}/apercu-italic-pro`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Apercu',
style: 'italic',
},
{
filePath: `${FONT_ASSET_PATH}/apercu-bold-pro`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Apercu',
weight: 'bold',
},
{
filePath: `${FONT_ASSET_PATH}/apercu-bold-italic-pro`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Apercu',
weight: 'bold',
style: 'italic',
},
{
filePath: `${FONT_ASSET_PATH}/SuisseIntlMono-Bold-WebS`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Suisse',
weight: 'bold',
},
{
filePath: `${FONT_ASSET_PATH}/SuisseIntlMono-Regular-WebS`,
extensions: ['woff', 'woff2'],
extensions: ['woff2', 'woff'],
name: 'Suisse',
},
];
Loading