diff --git a/index.ts b/index.ts
index 0b315aa..25320c1 100644
--- a/index.ts
+++ b/index.ts
@@ -1,9 +1,15 @@
import { ServerRequest } from "./deps.ts";
import { GithubAPIClient } from "./src/github_api_client.ts";
+import { Card } from "./src/card.ts";
import "https://deno.land/x/dotenv@v0.5.0/load.ts";
const client = new GithubAPIClient();
export default async (req: ServerRequest) => {
- const userInfo = await client.requestUserData("ryo-ma")
- req.respond({ body: `Hello, from Deno v${Deno.version.deno}!` + userInfo });
+ const userInfo = await client.requestUserInfo("ryo-ma")
+ req.respond(
+ {
+ body: new Card().render(),
+ headers: new Headers({ "Content-Type": "image/svg+xml" }),
+ },
+ )
};
diff --git a/src/card.ts b/src/card.ts
new file mode 100644
index 0000000..e45f1b7
--- /dev/null
+++ b/src/card.ts
@@ -0,0 +1,44 @@
+import { TotalStarTrophy, TotalCommitTrophy } from "./trophies.ts";
+
+export class Card {
+ constructor(private width = 1000, private height = 200) {
+ }
+ render(): string {
+ const trophy1 = new TotalStarTrophy(0);
+ const trophy2 = new TotalStarTrophy(100);
+ const trophy3 = new TotalStarTrophy(500);
+ const trophy4 = new TotalStarTrophy(1000);
+ const trophy5 = new TotalCommitTrophy(1);
+ const trophy6 = new TotalCommitTrophy(200);
+ const trophy7 = new TotalCommitTrophy(1000);
+ const trophy8 = new TotalCommitTrophy(5000);
+ return `
+ `;
+ }
+}
diff --git a/src/github_api_client.ts b/src/github_api_client.ts
index 878f3aa..58aa998 100644
--- a/src/github_api_client.ts
+++ b/src/github_api_client.ts
@@ -15,7 +15,7 @@ class UserInfo {
export class GithubAPIClient {
constructor() {
}
- async requestUserData(username: string): Promise {
+ async requestUserInfo(username: string): Promise {
const token = Deno.env.get('GITHUB_TOKEN');
const variables = { username: username };
const query = `
diff --git a/src/icons.ts b/src/icons.ts
index f6c90cc..3d58efe 100644
--- a/src/icons.ts
+++ b/src/icons.ts
@@ -1 +1,50 @@
-export const icons = "icons";
\ No newline at end of file
+export const icons = "icons";
+
+const goldColor = "#FFD700";
+const silverColor = "#C0C0C0";
+const bronzeColor = "#816D46";
+const leafIcon = ``
+export function getTropyIcon(rank = "?") {
+ let color = "currentColor"
+ let backgroundIcon = "";
+ if (rank == "S") {
+ color = goldColor;
+ backgroundIcon = leafIcon;
+ } else if (rank == "A") {
+ color = silverColor;
+ backgroundIcon = leafIcon;
+ } else if (rank == "B") {
+ color = bronzeColor;
+ }
+ return `
+ ${backgroundIcon}
+ `;
+}
diff --git a/src/trophies.ts b/src/trophies.ts
new file mode 100644
index 0000000..889bb20
--- /dev/null
+++ b/src/trophies.ts
@@ -0,0 +1,88 @@
+import { getTropyIcon } from "./icons.ts";
+
+abstract class Trophy {
+ rank: string = "?";
+ topMessage = "Unknown";
+ bottomMessage = "+0";
+ title = "";
+ abstract setRank(): void;
+ render(x = 0, y = 0): string {
+ return `
+
+ `;
+ }
+}
+
+export class TotalStarTrophy extends Trophy {
+ constructor(private totalStartgazer: Number) {
+ super();
+ this.title = "TOTAL STAR";
+ this.setRank();
+ }
+ setRank() {
+ if (this.totalStartgazer >= 1000) {
+ this.rank = "S";
+ this.topMessage = "Super Star +1000";
+ } else if (this.totalStartgazer >= 500) {
+ this.rank = "A";
+ this.topMessage = "High Star +500";
+ } else if (this.totalStartgazer >= 100) {
+ this.rank = "B";
+ this.topMessage = "Middle Star +100";
+ } else if (this.totalStartgazer >= 1) {
+ this.rank = "C";
+ this.topMessage = "First Star";
+ }
+ }
+}
+
+export class TotalCommitTrophy extends Trophy {
+ constructor(private totalStartgazer: Number) {
+ super();
+ this.title = "TOTAL COMMIT";
+ this.setRank();
+ }
+ setRank() {
+ if (this.totalStartgazer >= 5000) {
+ this.rank = "S";
+ this.topMessage = "Super commiter";
+ this.bottomMessage = "+5000";
+ } else if (this.totalStartgazer >= 1000) {
+ this.rank = "A";
+ this.topMessage = "High commiter";
+ this.bottomMessage = "+1000";
+ } else if (this.totalStartgazer >= 200) {
+ this.rank = "B";
+ this.topMessage = "Middle commiter";
+ this.bottomMessage = "+200";
+ } else if (this.totalStartgazer >= 1) {
+ this.rank = "C";
+ this.topMessage = "First commit";
+ this.bottomMessage = "+1";
+ }
+ }
+}