Skip to content

Commit

Permalink
Merge pull request #15 from willmanduffy/scrobble-top-weekly
Browse files Browse the repository at this point in the history
Skeet the weekly top artists
  • Loading branch information
willmanduffy authored Dec 7, 2024
2 parents 6c9667f + f31b5cd commit 389b719
Show file tree
Hide file tree
Showing 18 changed files with 973 additions and 10 deletions.
40 changes: 40 additions & 0 deletions fonthelper.js
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());
}
189 changes: 188 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"dependencies": {
"@atproto/api": "^0.13.18",
"@imikailoby/lastfm-ts": "^2.0.1",
"@kellnerd/listenbrainz": "npm:@jsr/kellnerd__listenbrainz@^0.8.4"
"@kellnerd/listenbrainz": "npm:@jsr/kellnerd__listenbrainz@^0.8.4",
"workers-og": "^0.0.25"
},
"scripts": {
"test": "vitest run"
Expand Down
Loading

0 comments on commit 389b719

Please sign in to comment.