Last active
April 5, 2019 21:57
-
-
Save alandbh/660a3b15762c940f8d201dc5381b5f58 to your computer and use it in GitHub Desktop.
Sass mixing for importing web-fonts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================================================================= | |
// String Replace | |
// ============================================================================= | |
@function str-replace($string, $search, $replace: '') { | |
$index: str-index($string, $search); | |
@if $index { | |
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace); | |
} | |
@return $string; | |
} | |
// ============================================================================= | |
// Font Face | |
// ============================================================================= | |
@mixin font-face($name, $path, $weight: null, $style: null, $exts: eot woff2 woff ttf svg) { | |
$src: null; | |
$extmods: ( eot: '?', svg: '#' + str-replace($name, ' ', '_') ); | |
$formats: ( otf: 'opentype', ttf: 'truetype' ); | |
@each $ext in $exts { | |
$extmod: if(map-has-key($extmods, $ext), $ext + map-get($extmods, $ext), $ext); | |
$format: if(map-has-key($formats, $ext), map-get($formats, $ext), $ext); | |
$src: append($src, url(quote($path + '.' + $extmod)) format(quote($format)), comma); | |
} | |
@font-face { | |
font-family: quote($name); | |
font-display: auto; | |
font-style: $style; | |
font-weight: $weight; | |
src: $src; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment