Script Mengunduh File CSS dengan font dan beradaptasi dengan bekerja di lingkungan tertutup/offline. Berguna misalnya ketika proyek harus dijalankan di jaringan tanpa koneksi dengan internet atau ketika Anda membuat aplikasi berdasarkan proyek seperti elektron.
Script dapat "diinstal" secara manual dengan mengkloning ./main.js file atau dengan npm:
npm install get-google-fonts
Misalnya CSS dengan font yang digunakan seperti ini:
< link href =' https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic ' rel =' stylesheet ' >Dapat diganti dengan:
< link href =' fonts/fonts.css ' rel =' stylesheet ' > Menggunakan baris perintah itu mungkin ketika skrip diinstal sebagai global atau Anda tahu jalur lengkap ke file cli.js Secara default, NPM akan lebih suka menginstal skrip sebagai global dan setelah itu skrip akan berbagi file dalam direktori bin bernama get-google-fonts . Maka Anda hanya bisa menggunakan perintah itu di mana saja.
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
Untuk mendapatkan hasil seperti dalam contoh, cukup masukkan perintah di folder dengan file html:
get-google-fonts -i "https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic"
Get-Google-font bisa diperlukan sebagai modul.
const GetGoogleFonts = require ( 'get-google-fonts' ) ; Untuk mendapatkan hasil seperti dalam contoh, cukup buat objek dan jalankan metode download .
new GetGoogleFonts ( ) . download ( 'https://fonts.googleapis.com/css?family=Roboto:400,700&subset=cyrillic' )
// => PromiseAda tiga metode yang berguna di semua modul.
Parameter:
config memungkinkan Anda untuk mengkonfigurasi semua unduhan yang dilakukan oleh objek ini. Lihat lebih lanjut ... [Opsional]Contoh:
let ggf_ttf = new GetGoogleFonts ( {
userAgent : 'Wget/1.18'
} )
let ggf_defaults = new GetGoogleFonts ( )Parameter:
url URL ke CSS sebagai objek font atau string biasa. Dapat berupa array argumen Penyihir akan dilewati melalui getGoogleFonts.constructurl ().config memungkinkan Anda untuk mengkonfigurasi unduhan yang satu ini. Lihat lebih lanjut ... [Opsional]Contoh:
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!' )
} )Hasilkan URL Google Font menggunakan parameter yang diberikan.
Parameter:
families objek nama dan bobot fontsubsets bagian himpunan bagianContoh:
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 Objek akan dipertimbangkan sebagai berikut: Unduh Config> GetGoOgleFonts Object 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
} Variabel berikut dapat digunakan dalam templat:
{comment} teks dari komentar ditempatkan sebelum @font-face. Google tempat ada nama subset misalnya latin{family} font-family misalnya sumber sans pro{_family} font-family (whitespace akan diganti dengan garis bawah) misalnya source_sans_pro{weight} font-weight misalnya 400{filename} Nama file asli misalnya odeli1ahbydbqgeih2zlc2q8seg17bfdxyr_jusrzg{ext} ekstensi asli misalnya woff2{i} angka yang bertambah satu per satu setiap kali file font ditambahkan. Berguna untuk mempertahankan keunikan nama font jika Anda tidak yakin apakah variabel sebelumnya sudah cukup. Itu dimulai dari 1. Proyek ini dilisensikan di bawah lisensi apache -2.0 - lihat file lisensi.md untuk detailnya