Skip to content

Commit

Permalink
refactor: use shields.io built-in JSR logo for badges (#487)
Browse files Browse the repository at this point in the history
The JSR logo has been added to Simple Icons since
simple-icons/simple-icons#10794.

I used the `logoSize` parameter to make the logo fit the badge. The
feature was introduced at badges/shields#9191.

Currently, we can't use `logoSize` in the response due to
badges/shields#10132. So I passed these
parameters with search parameters instead.
  • Loading branch information
LitoMore committed May 9, 2024
1 parent 7e28877 commit c784ee3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
8 changes: 3 additions & 5 deletions frontend/routes/badges/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ export const handler: Handlers<unknown, State> = {
return Response.json({
schemaVersion: 1,
label: "",
// namedLogo: "jsr", TODO: add icon to shields.io or simple-icons. temporary solution below.
logoSvg: await Deno.readTextFile(
new URL("../../static/logo.svg", import.meta.url),
),
message: packageResp.data.latestVersion,
labelColor: "rgb(247,223,30)",
color: "rgb(8,51,68)",
logoWidth: "25",
});
}
} else {
Expand All @@ -42,6 +37,9 @@ export const handler: Handlers<unknown, State> = {
const shieldsUrl = new URL("https://img.shields.io/endpoint");
shieldsUrl.search = url.search;
shieldsUrl.searchParams.set("url", url.href);
shieldsUrl.searchParams.set("logo", "jsr");
shieldsUrl.searchParams.set("logoColor", "rgb(8,51,68)");
shieldsUrl.searchParams.set("logoSize", "auto");

const res = await fetch(shieldsUrl);

Expand Down
8 changes: 3 additions & 5 deletions frontend/routes/badges/package_score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ export const handler: Handlers<unknown, State> = {
return Response.json({
schemaVersion: 1,
label: "",
// namedLogo: "jsr", TODO: add icon to shields.io or simple-icons. temporary solution below.
logoSvg: await Deno.readTextFile(
new URL("../../static/logo.svg", import.meta.url),
),
message: `${packageResp.data.score}%`,
labelColor: "rgb(247,223,30)",
color: "rgb(8,51,68)",
logoWidth: "25",
});
}
} else {
Expand All @@ -46,6 +41,9 @@ export const handler: Handlers<unknown, State> = {
const shieldsUrl = new URL("https://img.shields.io/endpoint");
shieldsUrl.search = url.search;
shieldsUrl.searchParams.set("url", url.href);
shieldsUrl.searchParams.set("logo", "jsr");
shieldsUrl.searchParams.set("logoColor", "rgb(8,51,68)");
shieldsUrl.searchParams.set("logoSize", "auto");

const res = await fetch(shieldsUrl);

Expand Down
8 changes: 3 additions & 5 deletions frontend/routes/badges/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ export const handler: Handlers<unknown, State> = {
return Response.json({
schemaVersion: 1,
label: "",
// namedLogo: "jsr", TODO: add icon to shields.io or simple-icons. temporary solution below.
logoSvg: await Deno.readTextFile(
new URL("../../static/logo.svg", import.meta.url),
),
message: `@${scopeResp.data.scope}`,
labelColor: "rgb(247,223,30)",
color: "rgb(8,51,68)",
logoWidth: "25",
});
}
} else {
Expand All @@ -42,6 +37,9 @@ export const handler: Handlers<unknown, State> = {
const shieldsUrl = new URL("https://img.shields.io/endpoint");
shieldsUrl.search = url.search;
shieldsUrl.searchParams.set("url", url.href);
shieldsUrl.searchParams.set("logo", "jsr");
shieldsUrl.searchParams.set("logoColor", "rgb(8,51,68)");
shieldsUrl.searchParams.set("logoSize", "auto");

const res = await fetch(shieldsUrl);

Expand Down

0 comments on commit c784ee3

Please sign in to comment.