mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Support margin option
This commit is contained in:
parent
3ceb08fce5
commit
f9e4a2a795
3 changed files with 16 additions and 14 deletions
12
index.ts
12
index.ts
|
|
@ -17,13 +17,13 @@ export default async (req: ServerRequest) => {
|
||||||
if (Object.keys(COLORS).includes(themeParam)) {
|
if (Object.keys(COLORS).includes(themeParam)) {
|
||||||
theme = COLORS[themeParam]
|
theme = COLORS[themeParam]
|
||||||
}
|
}
|
||||||
const paddingWidth = params.getNumberValue(
|
const marginWidth = params.getNumberValue(
|
||||||
"padding-w",
|
"margin-w",
|
||||||
CONSTANTS.DEFAULT_PADDING_W,
|
CONSTANTS.DEFAULT_MARGIN_W,
|
||||||
);
|
);
|
||||||
const paddingHeight = params.getNumberValue(
|
const paddingHeight = params.getNumberValue(
|
||||||
"padding-h",
|
"margin-h",
|
||||||
CONSTANTS.DEFAULT_PADDING_H,
|
CONSTANTS.DEFAULT_MARGIN_H,
|
||||||
);
|
);
|
||||||
const titles: Array<string> = params.getAll("title").flatMap((r) =>
|
const titles: Array<string> = params.getAll("title").flatMap((r) =>
|
||||||
r.split(",")
|
r.split(",")
|
||||||
|
|
@ -62,7 +62,7 @@ export default async (req: ServerRequest) => {
|
||||||
column,
|
column,
|
||||||
row,
|
row,
|
||||||
CONSTANTS.DEFAULT_PANEL_SIZE,
|
CONSTANTS.DEFAULT_PANEL_SIZE,
|
||||||
paddingWidth,
|
marginWidth,
|
||||||
paddingHeight,
|
paddingHeight,
|
||||||
).render(userInfo, theme),
|
).render(userInfo, theme),
|
||||||
headers: new Headers(
|
headers: new Headers(
|
||||||
|
|
|
||||||
14
src/card.ts
14
src/card.ts
|
|
@ -25,10 +25,10 @@ export class Card {
|
||||||
private maxColumn: number,
|
private maxColumn: number,
|
||||||
private maxRow: number,
|
private maxRow: number,
|
||||||
private panelSize: number,
|
private panelSize: number,
|
||||||
private paddingWidth: number,
|
private marginWidth: number,
|
||||||
private paddingHight: number,
|
private marginHight: number,
|
||||||
) {
|
) {
|
||||||
this.width = panelSize * this.maxColumn;
|
this.width = panelSize * this.maxColumn + this.marginWidth * (this.maxColumn - 1);
|
||||||
}
|
}
|
||||||
render(
|
render(
|
||||||
userInfo: UserInfo,
|
userInfo: UserInfo,
|
||||||
|
|
@ -83,13 +83,15 @@ export class Card {
|
||||||
if (row > this.maxRow) {
|
if (row > this.maxRow) {
|
||||||
row = this.maxRow;
|
row = this.maxRow;
|
||||||
}
|
}
|
||||||
this.height = this.panelSize * row;
|
this.height = this.panelSize * row + this.marginHight * (row - 1);
|
||||||
|
|
||||||
// Join all trophy
|
// Join all trophy
|
||||||
const renderedTrophy = trophyList.reduce(
|
const renderedTrophy = trophyList.reduce(
|
||||||
(sum: string, trophy: Trophy, i: number) => {
|
(sum: string, trophy: Trophy, i: number) => {
|
||||||
const x = this.panelSize * (i % this.maxColumn);
|
const currentColumn = i % this.maxColumn;
|
||||||
const y = this.panelSize * Math.floor(i / this.maxColumn);
|
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);
|
||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ export const CONSTANTS = {
|
||||||
DEFAULT_PANEL_SIZE: 110,
|
DEFAULT_PANEL_SIZE: 110,
|
||||||
DEFAULT_MAX_COLUMN: 6,
|
DEFAULT_MAX_COLUMN: 6,
|
||||||
DEFAULT_MAX_ROW: 3,
|
DEFAULT_MAX_ROW: 3,
|
||||||
DEFAULT_PADDING_W: 0,
|
DEFAULT_MARGIN_W: 0,
|
||||||
DEFAULT_PADDING_H: 0,
|
DEFAULT_MARGIN_H: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum RANK {
|
export enum RANK {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue