Skip to content

Instantly share code, notes, and snippets.

@nikitadmitr
Last active July 22, 2023 14:03
Show Gist options
  • Save nikitadmitr/0e5c1b102273ab4895b3f84dd5ea4b3d to your computer and use it in GitHub Desktop.
Save nikitadmitr/0e5c1b102273ab4895b3f84dd5ea4b3d to your computer and use it in GitHub Desktop.
font-adding-algorithm
$path-to-fonts: '../fonts';
$font-families: (
'FontName1': ((100, 'Thin'),
(200, 'ExtraLight'),
(300, 'Light'),
(400, 'Regular'),
(500, 'Medium'),
(600, 'SemiBold'),
(700, 'Bold'),
(800, 'ExtraBold'),
(900, 'Black')),
'FontName2': ((100, 'Thin'),
(200, 'ExtraLight'),
(300, 'Light'),
(400, 'Regular'),
(500, 'Medium'),
(600, 'SemiBold'),
(700, 'Bold'),
(800, 'ExtraBold'),
(900, 'Black')),
'FontName3': ((100, 'Thin'),
(200, 'ExtraLight'),
(300, 'Light'),
(400, 'Regular'),
(500, 'Medium'),
(600, 'SemiBold'),
(700, 'Bold'),
(800, 'ExtraBold'),
(900, 'Black'))
);
@each $font-family,
$weights in $font-families {
@each $weight in $weights {
$weight-number: nth($weight, 1);
$weight-name: nth($weight, 2);
@font-face {
font-family: $font-family;
font-style: normal;
font-weight: $weight-number;
src: url('#{$path-to-fonts}/#{$font-family}/#{$font-family}-#{$weight-name}.ttf') format('truetype');
}
@font-face {
font-family: $font-family;
font-style: italic;
font-weight: $weight-number;
src: url('#{$path-to-fonts}/#{$font-family}/#{$font-family}-#{$weight-name}Italic.ttf') format('truetype');
}
}
}
@nikitadmitr
Copy link
Author

You can read about here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment