スクリプトは、フォントを使用してCSSファイルをダウンロードし、閉じた環境/オフラインでの作業に適応します。たとえば、インターネットに接続せずにプロジェクトをネットワークで実行する必要がある場合、または電子などのプロジェクトに基づいてアプリケーションを作成する場合に役立ちます。
スクリプトは./main.jsファイルをCloningまたは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はグローバルとしてスクリプトをインストールすることを好み、その後、スクリプトはget-google-fontsという名前のBin Directoryでファイルを共有します。その後、そのコマンドをどこでも使用することができます。
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すべてのモジュールに3つの有用な方法があります。
パラメーター:
config使用すると、このオブジェクトによって実行されたすべてのダウンロードを事前に設定できます。詳細を見る... [オプション]例:
let ggf_ttf = new GetGoogleFonts ( {
userAgent : 'Wget/1.18'
} )
let ggf_defaults = new GetGoogleFonts ( )パラメーター:
url url。魔女は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オブジェクトconfig> default configをダウンロードします
// 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の場所Subsetの名前Eg Latin{family} font-family Eg source sans pro{_family} font-family(whitespaceはアンダースコアに置き換えられます)eg source_sans_pro{weight} font-weight eg 400{filename}元のファイルの名前EG ODELI1AHBYDBQGEIAH2ZLC2Q8SEG17BFDXYR_JUSRZG{ext}元の拡張子Eg Woff2{i}フォントファイルが追加されるたびに1つずつ増加する数字。以前の変数で十分かどうかわからない場合に備えて、フォント名の一意性を維持するのに役立ちます。 1から始まります。 このプロジェクトは、Apache -2.0ライセンスに基づいてライセンスされています - 詳細については、license.mdファイルを参照してください