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許可下獲得許可 - 有關詳細信息,請參見許可證。