mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Merge pull request #28 from kawarimidoll/feature/transparent
Feat: Transparent background and frame
This commit is contained in:
commit
f78fd47cea
5 changed files with 47 additions and 2 deletions
21
README.md
21
README.md
|
|
@ -96,6 +96,8 @@ Therefore, if you come up with interesting conditions, I am waiting for contribu
|
|||
* [theme](#apply-theme)
|
||||
* [margin-w](#margin-width)
|
||||
* [margin-h](#margin-height)
|
||||
* [no-bg](#transpalent-background)
|
||||
* [no-frame](#hide-frame)
|
||||
|
||||
|
||||
## Filter by titles
|
||||
|
|
@ -301,6 +303,25 @@ https://github-profile-trophy.vercel.app/?username=ryo-ma&column=3&margin-w=15&m
|
|||
<img width="360" src="https://user-images.githubusercontent.com/6661165/93668677-ff309a80-fac8-11ea-8ae3-3e3e8adbef39.png">
|
||||
</p>
|
||||
|
||||
## Transpalent background
|
||||
|
||||
You can turn the background transparent.
|
||||
`Available value: boolean type (true or false)`
|
||||
`Default: no-bg=false`
|
||||
|
||||
```
|
||||
https://github-profile-trophy.vercel.app/?username=ryo-ma&no-bg=true
|
||||
```
|
||||
|
||||
## Hide frames
|
||||
|
||||
You can hide the frames around the trophies.
|
||||
`Available value: boolean type (true or false)`
|
||||
`Default: no-frame=false`
|
||||
|
||||
```
|
||||
https://github-profile-trophy.vercel.app/?username=ryo-ma&no-frame=true
|
||||
```
|
||||
|
||||
# Contribution Guide
|
||||
|
||||
|
|
|
|||
10
index.ts
10
index.ts
|
|
@ -25,6 +25,14 @@ export default async (req: ServerRequest) => {
|
|||
"margin-h",
|
||||
CONSTANTS.DEFAULT_MARGIN_H,
|
||||
);
|
||||
const noBackground = params.getBooleanValue(
|
||||
"no-bg",
|
||||
CONSTANTS.DEFAULT_NO_BACKGROUND,
|
||||
);
|
||||
const noFrame = params.getBooleanValue(
|
||||
"no-frame",
|
||||
CONSTANTS.DEFAULT_NO_FRAME,
|
||||
);
|
||||
const titles: Array<string> = params.getAll("title").flatMap((r) =>
|
||||
r.split(",")
|
||||
).map((r) => r.trim());
|
||||
|
|
@ -64,6 +72,8 @@ export default async (req: ServerRequest) => {
|
|||
CONSTANTS.DEFAULT_PANEL_SIZE,
|
||||
marginWidth,
|
||||
paddingHeight,
|
||||
noBackground,
|
||||
noFrame,
|
||||
).render(userInfo, theme),
|
||||
headers: new Headers(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ export class Card {
|
|||
private panelSize: number,
|
||||
private marginWidth: number,
|
||||
private marginHight: number,
|
||||
private noBackground: boolean,
|
||||
private noFrame: boolean,
|
||||
) {
|
||||
this.width = panelSize * this.maxColumn + this.marginWidth * (this.maxColumn - 1);
|
||||
}
|
||||
|
|
@ -92,7 +94,7 @@ export class Card {
|
|||
const currentRow = Math.floor(i / this.maxColumn);
|
||||
const x = this.panelSize * currentColumn + this.marginWidth * currentColumn;
|
||||
const y = this.panelSize * currentRow + this.marginHight * currentRow;
|
||||
return sum + trophy.render(theme, x, y, this.panelSize);
|
||||
return sum + trophy.render(theme, x, y, this.panelSize, this.noBackground, this.noFrame);
|
||||
},
|
||||
"",
|
||||
);
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ export class Trophy {
|
|||
x = 0,
|
||||
y = 0,
|
||||
panelSize = CONSTANTS.DEFAULT_PANEL_SIZE,
|
||||
noBackground = CONSTANTS.DEFAULT_NO_BACKGROUND,
|
||||
noFrame = CONSTANTS.DEFAULT_NO_FRAME,
|
||||
): string {
|
||||
const { BACKGROUND: PRIMARY, TITLE: SECONDARY, TEXT, NEXT_RANK_BAR } = theme;
|
||||
const nextRankBar = getNextRankBar(
|
||||
|
|
@ -88,7 +90,8 @@ export class Trophy {
|
|||
height="${panelSize - 1}"
|
||||
stroke="#e1e4e8"
|
||||
fill="${PRIMARY}"
|
||||
stroke-opacity="1"
|
||||
stroke-opacity="${noFrame ? '0' : '1'}"
|
||||
fill-opacity="${noBackground ? '0' : '1'}"
|
||||
/>
|
||||
${getTrophyIcon(theme, this.rank)}
|
||||
<text x="50%" y="18" text-anchor="middle" font-family="Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji" font-weight="bold" font-size="13" fill="${SECONDARY}">${this.title}</text>
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@ export class CustomURLSearchParams extends URLSearchParams {
|
|||
}
|
||||
return defaultValue;
|
||||
}
|
||||
getBooleanValue(key: string, defaultValue: boolean): boolean {
|
||||
if (super.has(key)) {
|
||||
const param = super.get(key);
|
||||
return param !== null && param.toString() === 'true';
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
export function parseParams(req: ServerRequest): CustomURLSearchParams {
|
||||
|
|
@ -55,6 +62,8 @@ export const CONSTANTS = {
|
|||
DEFAULT_MAX_ROW: 3,
|
||||
DEFAULT_MARGIN_W: 0,
|
||||
DEFAULT_MARGIN_H: 0,
|
||||
DEFAULT_NO_BACKGROUND: false,
|
||||
DEFAULT_NO_FRAME: false,
|
||||
};
|
||||
|
||||
export enum RANK {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue