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.
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]
18 fail('Pass the name of the font family as an argument. It is case-sensitive.')
22 const response = await fetch(`https://fonts.googleapis.com/css2?family=${fontFamilyName}&display=swap`, {
23 "credentials": "omit",
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"
35 const css = await response.text()
37 css.replace(/https?:[^)]*/g, (str) => {
41 console.log(`Use this URL for the font family ${fontFamilyName}:`)
42 console.log(urls.join('\n'))
44 fail('Could not parse font URLs from Google Fonts css file.')
47 fail(`Could not find font family ${fontFamilyName}. Check its spelling and case and that it exists on Google Fonts.`)
51function fail(message) {
52 console.error(message)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list