Skip to content

Commit d1322e9

Browse files
authored
feat(#626): Allow specifying logoColor when generating badge (#629)
In this PR: - Allow specifying `logoColor` when generating badge, fallback to `rgb(8,51,68)` if none is explicitly set, resolves #626 - Update documentation - Update e2e tests
1 parent cb7f609 commit d1322e9

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed

e2e/main_test.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,17 @@ Deno.test("[GET /badges/@luca/flag] works", async (t) => {
332332
assertNotMatch(text, /please use https/);
333333
});
334334

335-
// Skipping: These are not registered with shields.io yet
336-
// await t.step("Package score badge", async () => {
337-
// const res = await fetch(`${JSR_URL}badges/@luca/flag/score`);
338-
// const text = await res.text();
339-
// assertEquals(res.status, 200);
340-
// assertNotMatch(text, /please use https/);
341-
// });
335+
await t.step("Package score badge", async () => {
336+
const res = await fetch(`${JSR_URL}badges/@luca/flag/score`);
337+
const text = await res.text();
338+
assertEquals(res.status, 200);
339+
assertNotMatch(text, /please use https/);
340+
});
342341

343-
// await t.step("Scope badge", async () => {
344-
// const res = await fetch(`${JSR_URL}badges/@luca`);
345-
// const text = await res.text();
346-
// assertEquals(res.status, 200);
347-
// assertNotMatch(text, /please use https/);
348-
// });
342+
await t.step("Scope badge", async () => {
343+
const res = await fetch(`${JSR_URL}badges/@luca`);
344+
const text = await res.text();
345+
assertEquals(res.status, 200);
346+
assertNotMatch(text, /please use https/);
347+
});
349348
});

frontend/docs/badges.md

+19
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,22 @@ To include it in a Markdown document, use the following code, replacing
8686
<img src="https://jsr.io/badges/@<scope>" alt="" />
8787
</a>
8888
```
89+
90+
## Custom Badge Styling
91+
92+
These badges can be customized by adding query parameters to the URL, for
93+
example:
94+
95+
```
96+
https://jsr.io/badges/@<scope>/<package>?color=blue&labelColor=121212&logoColor=red
97+
```
98+
99+
Here's how it looks:
100+
101+
[![JSR Scope](https://jsr.io/badges/@luca?color=blue&labelColor=121212&logoColor=red)](https://jsr.io/@luca)
102+
103+
The supported style-related query parameters can be found in the
104+
[Shields.io documentation](https://shields.io/badges/endpoint-badge#:~:text=Query%20Parameters).
105+
106+
> Note: `logoSize`, `logo`, `url` and `cacheSeconds` are not supported and if
107+
> provided, they will be ignored.

frontend/routes/badges/package.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ export const handler: Handlers<unknown, State> = {
3737
shieldsUrl.search = url.search;
3838
shieldsUrl.searchParams.set("url", url.href);
3939
shieldsUrl.searchParams.set("logo", "jsr");
40-
shieldsUrl.searchParams.set("logoColor", "rgb(8,51,68)");
4140
shieldsUrl.searchParams.set("logoSize", "auto");
4241
shieldsUrl.searchParams.set("cacheSeconds", "300");
4342

43+
if (!ctx.url.searchParams.has("logoColor")) {
44+
shieldsUrl.searchParams.set("logoColor", "rgb(8,51,68)");
45+
}
46+
4447
const res = await fetch(shieldsUrl);
4548

4649
return new Response(res.body, {

frontend/routes/badges/package_score.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ export const handler: Handlers<unknown, State> = {
4141
shieldsUrl.search = url.search;
4242
shieldsUrl.searchParams.set("url", url.href);
4343
shieldsUrl.searchParams.set("logo", "jsr");
44-
shieldsUrl.searchParams.set("logoColor", "rgb(8,51,68)");
4544
shieldsUrl.searchParams.set("logoSize", "auto");
4645
shieldsUrl.searchParams.set("cacheSeconds", "300");
4746

48-
console.log(shieldsUrl.href);
47+
if (!ctx.url.searchParams.has("logoColor")) {
48+
shieldsUrl.searchParams.set("logoColor", "rgb(8,51,68)");
49+
}
4950

5051
const res = await fetch(shieldsUrl);
5152

frontend/routes/badges/scope.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ export const handler: Handlers<unknown, State> = {
3737
shieldsUrl.search = url.search;
3838
shieldsUrl.searchParams.set("url", url.href);
3939
shieldsUrl.searchParams.set("logo", "jsr");
40-
shieldsUrl.searchParams.set("logoColor", "rgb(8,51,68)");
4140
shieldsUrl.searchParams.set("logoSize", "auto");
4241
shieldsUrl.searchParams.set("cacheSeconds", "300");
4342

43+
if (!ctx.url.searchParams.has("logoColor")) {
44+
shieldsUrl.searchParams.set("logoColor", "rgb(8,51,68)");
45+
}
46+
4447
const res = await fetch(shieldsUrl);
4548

4649
return new Response(res.body, {

0 commit comments

Comments
 (0)