-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from willmanduffy/scrobble-top-weekly
Skeet the weekly top artists
- Loading branch information
Showing
18 changed files
with
973 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// https://github.com/kvnang/workers-og/blob/main/packages/workers-og/src/font.ts | ||
const fs = require("fs"); | ||
async function loadGoogleFont({ family, weight, text }) { | ||
const params = { | ||
family: `${encodeURIComponent(family)}${weight ? `:wght@${weight}` : ""}`, | ||
}; | ||
|
||
if (text) { | ||
params.text = text; | ||
} else { | ||
params.subset = "latin"; | ||
} | ||
|
||
const url = `https://fonts.googleapis.com/css2?${Object.keys(params) | ||
.map((key) => `${key}=${params[key]}`) | ||
.join("&")}`; | ||
|
||
let res = await fetch(`${url}`, { | ||
headers: { | ||
// construct user agent to get TTF font | ||
"User-Agent": | ||
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1", | ||
}, | ||
}); | ||
|
||
res = new Response(res.body, res); | ||
res.headers.append("Cache-Control", "s-maxage=3600"); | ||
|
||
const body = await res.text(); | ||
// Get the font URL from the CSS text | ||
const fontUrl = body.match( | ||
/src: url\((.+)\) format\('(opentype|truetype)'\)/, | ||
)?.[1]; | ||
|
||
if (!fontUrl) { | ||
throw new Error("Could not find font URL"); | ||
} | ||
|
||
return fetch(fontUrl).then((res) => res.arrayBuffer()); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.