git.iko.soy/rowtype-yoga/yoga-r3f
on main help sign in
56 lines 1.7 kB history raw
1#!/usr/bin/env node
3/* eslint-disable */
5// Utility for finding the public URL for a font hosted on Google Fonts. Takes the font
6// family name and returns the URL to its .woff file.
8// TODO:
9// - Add ability to download the file for self-hosting
10// - Add options for font weights, italic, etc. and character subsets
12const fetch = require('node-fetch')
14const args = process.argv.slice(2)
16const fontFamilyName = args[0]
17if (!fontFamilyName) {
18 fail('Pass the name of the font family as an argument. It is case-sensitive.')
21async function run() {
22 const response = await fetch(`https://fonts.googleapis.com/css2?family=${fontFamilyName}&display=swap`, {
23 "credentials": "omit",
24 "headers": {
25 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko",
26 "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
27 "Accept-Language": "en-US,en;q=0.5",
28 "Upgrade-Insecure-Requests": "1",
29 "Cache-Control": "max-age=0"
30 },
31 "method": "GET",
32 //"mode": "cors"
33 })
34 if (response.ok) {
35 const css = await response.text()
36 const urls = []
37 css.replace(/https?:[^)]*/g, (str) => {
38 urls.push(str)
39 })
40 if (urls.length) {
41 console.log(`Use this URL for the font family ${fontFamilyName}:`)
42 console.log(urls.join('\n'))
43 } else {
44 fail('Could not parse font URLs from Google Fonts css file.')
45 }
46 } else {
47 fail(`Could not find font family ${fontFamilyName}. Check its spelling and case and that it exists on Google Fonts.`)
48 }
51function fail(message) {
52 console.error(message)
53 process.exit(1)
56run()