Skip to content

Instantly share code, notes, and snippets.

@jankal
Created September 9, 2020 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jankal/878211646188c8fb90ed83e2eb112807 to your computer and use it in GitHub Desktop.
Save jankal/878211646188c8fb90ed83e2eb112807 to your computer and use it in GitHub Desktop.
SCSS Font-Map Mixin
@mixin fontMap($fontPath, $font, $fontData) {
@each $name, $attributes in $fontData {
$src: null;
$exts: ("woff2": "woff2", "woff": "woff", "ttf": "truetype");
@if map-get($attributes, "hasOtf") {
$exts: map-merge($exts, ("otf": "opentype"));
}
@each $ext, $mime in $exts {
$src: append($src, url("#{$fontPath}/#{$name}/#{$font}-#{$name}.#{$ext}") format($mime), comma);
}
@font-face {
font: {
family: $font;
style: map-get($attributes, "style");
weight: map-get($attributes, "weight");;
}
src: $src;
}
}
}
$fontPath: "~assets/fonts/Montserrat";
$montserratFontData: (
"Medium": (
"weight": 500,
"style": normal,
"hasOtf": false
),
"MediumItalic": (
"weight": 500,
"style": italic,
"hasOtf": false
),
"SemiBold": (
"weight": 700,
"style": normal,
"hasOtf": false
),
"SemiBoldItalic": (
"weight": 700,
"style": italic,
"hasOtf": false
),
);
@include fontMap($fontPath, "Montserrat", $montserratFontData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment