Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new parameter (center) #280

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async function app(req: Request): Promise<Response> {
const ranks: Array<string> = params.getAll("rank").flatMap((r) =>
r.split(",")
).map((r) => r.trim());
const center: boolean = params.getBooleanValue("center", CONSTANTS.DEFAULT_CENTER)

if (username === null) {
const [base] = req.url.split("?");
Expand All @@ -81,23 +82,9 @@ async function app(req: Request): Promise<Response> {
<form action="https://github-profile-trophy.vercel.app/" method="get">
<label for="username">GitHub Username</label>
<input type="text" name="username" id="username" placeholder="Ex. gabriel-logan" required>
<button type="submit">Get Trophy&apos;s</button>
<button type="submit">Get Trophies</button>
</form>
</div>
<script>
const base = "https://github-profile-trophy.vercel.app/";
const button = document.querySelector("button");
const input = document.querySelector("input");
const temporarySpan = document.querySelector("#temporary-span");

button.addEventListener("click", () => {
navigator.clipboard.writeText(document.querySelector("#base-show").textContent);
temporarySpan.textContent = "Copied!";
setTimeout(() => {
temporarySpan.textContent = "";
}, 1500);
});
</script>
</section>`,
);
return new Response(
Expand Down Expand Up @@ -139,6 +126,7 @@ async function app(req: Request): Promise<Response> {
paddingHeight,
noBackground,
noFrame,
center
).render(userInfo, theme),
{
headers: defaultHeaders,
Expand Down
18 changes: 9 additions & 9 deletions src/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class Card {
private marginHeight: number,
private noBackground: boolean,
private noFrame: boolean,
private center: boolean,
) {
this.width = panelSize * this.maxColumn +
this.marginWidth * (this.maxColumn - 1);
Expand Down Expand Up @@ -53,17 +54,16 @@ export class Card {
const row = this.getRow(trophyList);
this.height = this.getHeight(row);

const style = this.center ? "display: block; margin: auto;" : "";

return `
<svg
width="${this.width}"
height="${this.height}"
viewBox="0 0 ${this.width} ${this.height}"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
${this.renderTrophy(trophyList, theme)}
</svg>`;
<svg xmlns="http://www.w3.org/2000/svg" style="height:${this.height}px;width:${this.width}px;${style}">
<svg xmlns="http://www.w3.org/2000/svg">
${this.renderTrophy(trophyList, theme)}
</svg>
</svg>`;
}

private getRow(trophyList: TrophyList) {
let row = Math.floor((trophyList.length - 1) / this.maxColumn) + 1;
if (row > this.maxRow) {
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const CONSTANTS = {
DEFAULT_GITHUB_RETRY_DELAY: 1000,
REVALIDATE_TIME: HOUR_IN_MILLISECONDS,
REDIS_TTL: HOUR_IN_MILLISECONDS * 4,
DEFAULT_CENTER: false,
};

export enum RANK {
Expand Down