@dima89e

Как подключить этот font-face генератор?

Просто там 3 аргумента, а я хочу несколько там жирных шрифтов подключить.
Вот код SCSS:

$fonts: () !default;

$font-file-types: 'woff' !default;

$fonts-path: '../fonts' !default;


@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;
}

@mixin generate-font-face(
	$font-family,
	$src,
	$font-weight,
	$font-style: normal
) {
	@font-face {
		font-family: $font-family;
		src: $src;
		font-weight: $font-weight;
		font-style: $font-style;
		@content;
	}
}

@function fontSrc(
	$fonts-path,
	$font-family,
	$font-file,
	$font-types: $font-file-types
) {
	$src: (local('☺'));
	$family-folder: str-replace($font-family, ' ', '-');
	@each $type in $font-types {
		$format-type: $type;
		@if $type == 'ttf' {
			$format-type: 'truetype';
		}
		@if $type == 'otf' {
			$format-type: 'opentype';
		}
		$src: append(
			$src,
			url('#{$fonts-path}/#{$family-folder}/#{nth($font-file, 1)}.#{$type}')
				format('#{$format-type}'),
			'comma'
		);
	}
	@return $src;
}

@mixin font-face($fonts: $fonts, $types: $font-file-types, $path: $fonts-path) {
	@each $font-family, $font-set in $fonts {
		@each $font-weight, $font-file in $font-set {
			@if type-of($font-file) == 'string' {
				$src: fontSrc($path, $font-family, $font-file, $types);
				@include generate-font-face($font-family, $src, $font-weight) {
					@content;
				}
			} @else {
				@each $font-style, $file in $font-file {
					$src: fontSrc($path, $font-family, $file, $types);
					@include generate-font-face(
						$font-family,
						$src,
						$font-weight,
						$font-style
					) {
						@content;
					}
				}
			}
		}
	}
}
  • Вопрос задан
  • 74 просмотра
Решения вопроса 1
@MaUg_Li
Зачем так много форматов тянуть?
Достаточно будет woff и woff2.

Если нужно супер старые браузеры поддерживать добавь ещё .eot

Зачем изобретать велосипед?
https://gist.github.com/jonathantneal/d0460e5c2d5d...
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы