get google fonts
1.0.0
脚本下载带字体的CSS文件,并将其调整为在封闭的环境/离线中工作。例如,当必须在网络中运行项目而无需与Internet连接或根据电子等项目进行应用程序时,很有用。
可以通过克隆./main.js文件或使用NPM手动“安装”脚本:
npm install get-google-fonts
例如,使用类似字体的CSS:
< link href =' https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic ' rel =' stylesheet ' >可以替换:
< link href =' fonts/fonts.css ' rel =' stylesheet ' > 使用命令行时,可以将脚本安装为global ,或者您知道cli.js文件的完整路径。默认情况下,NPM希望将脚本安装为Global,此后,脚本将在名为get-google-fonts bin目录中共享文件。然后,您可以在任何地方使用该命令。
Usage:
get-google-fonts [OPTIONS] [ARGS]
Options:
-i, --input URL Input URL of CSS with fonts
-o, --output [STRING] Output directory (Default is ./fonts)
-p, --path [STRING] Path placed before every source of font in CSS (Default is ./)
-c, --css [STRING] Name of CSS file (Default is fonts.css)
-t, --template [STRING] Template of font filename (Default is {_family}-{weight}-{comment}{i}.{ext})
-u, --useragent STRING User-agent used at every connection
-q, --quiet Don't displays a lot of useful information
-b, --base64 Save fonts inside CSS file as base64 URIs
--non-strict-ssl Force to accepts only valid SSL certificates; in some
cases,such proxy or self-signed certificates
should be turned off
-w, --overwriting Allows overwrite existing files
--print-options Shows result options object without performing any
action
-s, --simulate Simulation; No file will be saved
-h, --help Display help and usage details
为了获得例如例如,只需使用HTML文件在文件夹中输入命令:
get-google-fonts -i "https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic"
可以作为模块需要Get-Google-Fonts。
const GetGoogleFonts = require ( 'get-google-fonts' ) ;为了获取结果,例如创建对象并运行download方法。
new GetGoogleFonts ( ) . download ( 'https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic' )
// => Promise所有模块中都有三种有用的方法。
参数:
config允许您预先配置此对象完成的所有下载。查看更多... [可选]例子:
let ggf_ttf = new GetGoogleFonts ( {
userAgent : 'Wget/1.18'
} )
let ggf_defaults = new GetGoogleFonts ( )参数:
url URL到CSS。可以是巫婆的一系列参数将通过getgooglefonts.constructurl()传递。config允许您配置此下载。查看更多... [可选]例子:
ggf . download ( [
{
Roboto : [ 400 , 700 ]
} ,
[ 'cyrillic' ]
] ) . then ( ( ) => {
console . log ( 'Done!' )
} ) . catch ( ( ) => {
console . log ( 'Whoops!' )
} )
// or
ggf . download ( 'https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic' , {
userAgent : 'Wget/1.18'
} ) . then ( ( ) => {
console . log ( 'Done!' )
} ) . catch ( ( ) => {
console . log ( 'Whoops!' )
} )使用给定参数生成Google字体的URL。
参数:
families对象的字体名称和权重的对象subsets阵列例子:
GetGoogleFonts . constructUrl (
{
Roboto : [ '400' , 700 ] ,
'Roboto' : [ 400 , '700i' ] ,
'Alegreya Sans SC' : [ 300 ]
} ,
[ 'cyrillic' ]
)
// => https://fonts.googleapis.com/css?family=Roboto:400,700,700i|Alegreya+Sans+SC:300&subset=cyrillic 对象将如下:下载config> getgooglefonts对象配置>默认配置
// Default config object
{
// Output directory when where all files will be saved.
// According to this path, relative paths will be resolved.
outputDir : './fonts' ,
// Path placed before every source of font in CSS.
// It's also can be URL of your website.
path : './' ,
// Template of font filename.
template : '{_family}-{weight}-{comment}{i}.{ext}' ,
// Name of CSS file. Like other files
// will be placed relative to output directory
cssFile : 'fonts.css' ,
// User-agent used at every connection. Accordingly, Google Fonts will
// send the appropriate fonts. For example, providing a wget's
// user-agent will end with the download of .ttf fonts.
// Default user-agent downloads .woff2 fonts.
userAgent : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' +
'(KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36' ,
// Save fonts inside CSS file as base64 URIs
base64 : false ,
// Force to accepts only valid SSL certificates; in some cases,
// such proxy or self-signed certificates should be turned off
strictSSL : true ,
// Allows overwrite existing files.
overwriting : false ,
// Displays a lot of useful information.
verbose : false ,
// Simulation; No file will be saved.
simulate : false
} 以下变量可以在模板中使用:
{comment}来自 @font-face之前的评论中的文本。 Google Place subset的名称,例如拉丁语{family}字体家庭{_family} font-fonty(Whitespace将被下划线替换),例如source_sans_pro{weight}字体重量,例如400{filename}原始文件的名称,例如odeli1ahbydbqgeiah2zlc2q8seg17bfdxyr_jusrzg{ext}原始扩展,例如woff2{i}每次添加字体文件时,一个数字一次。对于保留字体名称的唯一性,如果您不确定先前的变量是否足够,则很有用。它从1开始。 该项目已在Apache -2.0许可下获得许可 - 有关详细信息,请参见许可证。