-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdl2.cjs
More file actions
27 lines (25 loc) · 1.08 KB
/
dl2.cjs
File metadata and controls
27 lines (25 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const https = require('https');
const fs = require('fs');
https.get('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@700&display=swap', {
headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' }
}, (res) => {
let d = '';
res.on('data', c => d += c);
res.on('end', () => {
// get all woff2 urls
const matches = d.match(/url\((https:[^)]+\.woff2)\)/g);
if (!matches) {
console.log('No matches found. CSS:', d);
return;
}
const urls = matches.map(u => u.slice(4, -1));
const finalUrl = urls[urls.length - 1]; // last one is usually latin
console.log('Fetching WOFF2 from:', finalUrl);
fs.mkdirSync('public/fonts', { recursive: true });
https.get(finalUrl, (r2) => {
const file = fs.createWriteStream('public/fonts/CormorantGaramond-Bold.woff2');
r2.pipe(file);
file.on('finish', () => console.log('DONE DOWNLOADING WOFF2'));
});
});
});