-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdl.js
More file actions
32 lines (28 loc) · 1.37 KB
/
dl.js
File metadata and controls
32 lines (28 loc) · 1.37 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
28
29
30
31
32
const https = require('https');
const fs = require('fs');
const url = 'https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@700&display=swap';
console.log("Fetching CSS...");
https.get(url, { headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' } }, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
// Find Latin woff2 block
const matches = [...data.matchAll(/url\((https:\/\/fonts\.gstatic\.com\/s\/[^\)]+\.woff2)\)/g)];
if (matches.length > 0) {
// Get the last one, usually the generic latin subset
const woff2Url = matches[matches.length - 1][1];
console.log('Downloading from:', woff2Url);
fs.mkdirSync('public/fonts', { recursive: true });
const file = fs.createWriteStream('public/fonts/CormorantGaramond-Bold.woff2');
https.get(woff2Url, (res2) => {
res2.pipe(file);
file.on('finish', () => {
file.close();
console.log('DOWNLOAD_SUCCESS: public/fonts/CormorantGaramond-Bold.woff2');
});
}).on('error', e => console.error("Error downloading file:", e));
} else {
console.log("NO URL MATCH FOUND IN CSS:", data);
}
});
}).on('error', e => console.error("Error fetching CSS:", e));