Last active
August 15, 2021 12:32
-
-
Save carlfranz/b684b83361c5aba841330ef5771da118 to your computer and use it in GitHub Desktop.
Script for importing a font into css
This file contains hidden or 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
| #!/usr/bin/perl | |
| use 5.010; | |
| use strict; | |
| use warnings; | |
| use Data::Dumper; | |
| my $family = 'OpenSans'; | |
| my @entries = ( | |
| [ "OpenSans-Semibold", "600", "normal" ], | |
| [ "OpenSans-SemiboldItalic", "600", "italic" ], | |
| [ "OpenSans-Light", "100", "normal" ], | |
| [ "OpenSans-LightItalic", "100", "italic" ], | |
| [ "OpenSans-Italic", "normal", "italic" ], | |
| [ "OpenSans-ExtraBold", "900", "normal" ], | |
| [ "OpenSans-ExtraBoldItalic", "900", "italic" ], | |
| [ "OpenSans-Bold", "bold", "normal" ], | |
| [ "OpenSans-BoldItalic", "bold", "italic" ], | |
| [ "OpenSans-Regular", "normal", "normal" ], | |
| ); | |
| for my $entry (@entries) { | |
| my $style = $entry->[2]; | |
| my $weight = $entry->[1]; | |
| my $filename = $entry->[0]; | |
| (my $localname = $filename) =~ s/-/ /; | |
| my $output = qq|\@font-face {\n|; | |
| $output = qq|${output} font-family: ${family};\n|; | |
| $output = qq|${output} font-style: ${style};\n|; | |
| $output = qq|${output} font-weight: ${weight};\n|; | |
| $output = qq|${output} src: local("${localname}"),\n|; | |
| $output = qq|${output} url("~src/assets/fonts/${filename}-webfont.woff") format("woff"),\n|; | |
| $output = qq|${output} url("~src/assets/fonts/${filename}-webfont.ttf") format("truetype"),\n|; | |
| $output = qq|${output} url("~src/assets/fonts/${filename}-webfont.eot") format("embedded-opentype");\n|; | |
| $output = qq|${output} unicode-range: U+000-5FF; /* Latin glyphs */\n|; | |
| $output = qq|${output}\}\n|; | |
| print $output; | |
| # print Dumper $entry; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment