mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Add multiple lang trophy
This commit is contained in:
parent
b1babb507c
commit
2153e390c9
4 changed files with 69 additions and 13 deletions
|
|
@ -6,9 +6,10 @@ import {
|
||||||
TotalIssueTrophy,
|
TotalIssueTrophy,
|
||||||
TotalPullRequestTrophy,
|
TotalPullRequestTrophy,
|
||||||
TotalRepositoryTrophy,
|
TotalRepositoryTrophy,
|
||||||
|
MultipleLangTrophy
|
||||||
} from "./trophies.ts";
|
} from "./trophies.ts";
|
||||||
import { UserInfo } from "./github_api_client.ts";
|
import { UserInfo } from "./github_api_client.ts";
|
||||||
import { CONSTANTS, RANK_ORDER } from "./utils.ts";
|
import { CONSTANTS, RANK_ORDER, RANK } from "./utils.ts";
|
||||||
|
|
||||||
export class Card {
|
export class Card {
|
||||||
private width = 0;
|
private width = 0;
|
||||||
|
|
@ -30,8 +31,12 @@ export class Card {
|
||||||
new TotalIssueTrophy(userInfo.totalIssues),
|
new TotalIssueTrophy(userInfo.totalIssues),
|
||||||
new TotalPullRequestTrophy(userInfo.totalPullRequests),
|
new TotalPullRequestTrophy(userInfo.totalPullRequests),
|
||||||
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
||||||
|
new MultipleLangTrophy(userInfo.languageCount),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Filter by hidden
|
||||||
|
trophyList = trophyList.filter((trophy) => !trophy.hidden || trophy.rank !== RANK.UNKNOWN);
|
||||||
|
|
||||||
// Filter by titles
|
// Filter by titles
|
||||||
if (this.titles.length != 0) {
|
if (this.titles.length != 0) {
|
||||||
trophyList = trophyList.filter((trophy) => this.titles.includes(trophy.title))
|
trophyList = trophyList.filter((trophy) => this.titles.includes(trophy.title))
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ export class UserInfo {
|
||||||
public totalStargazers: number,
|
public totalStargazers: number,
|
||||||
public totalRepositories: number,
|
public totalRepositories: number,
|
||||||
public totalContributed: number,
|
public totalContributed: number,
|
||||||
|
public languageCount: number
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -42,6 +43,11 @@ export class GithubAPIClient {
|
||||||
repositories(first: 100, ownerAffiliations: OWNER, isFork: false, orderBy: {direction: DESC, field: STARGAZERS}) {
|
repositories(first: 100, ownerAffiliations: OWNER, isFork: false, orderBy: {direction: DESC, field: STARGAZERS}) {
|
||||||
totalCount
|
totalCount
|
||||||
nodes {
|
nodes {
|
||||||
|
languages(first: 1, orderBy: {direction:DESC, field: SIZE}) {
|
||||||
|
nodes {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
stargazers {
|
stargazers {
|
||||||
totalCount
|
totalCount
|
||||||
}
|
}
|
||||||
|
|
@ -63,6 +69,13 @@ export class GithubAPIClient {
|
||||||
const totalStargazers = userData.repositories.nodes.reduce((prev: number, node: any) => {
|
const totalStargazers = userData.repositories.nodes.reduce((prev: number, node: any) => {
|
||||||
return prev + node.stargazers.totalCount;
|
return prev + node.stargazers.totalCount;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
const languages = new Set<string>();
|
||||||
|
userData.repositories.nodes.forEach((node: any)=> {
|
||||||
|
if (node.languages.nodes[0] != undefined) {
|
||||||
|
languages.add(node.languages.nodes[0].name)
|
||||||
|
}
|
||||||
|
});
|
||||||
const userInfo = new UserInfo(
|
const userInfo = new UserInfo(
|
||||||
totalCommits,
|
totalCommits,
|
||||||
userData.followers.totalCount,
|
userData.followers.totalCount,
|
||||||
|
|
@ -71,6 +84,7 @@ export class GithubAPIClient {
|
||||||
totalStargazers,
|
totalStargazers,
|
||||||
userData.repositories.totalCount,
|
userData.repositories.totalCount,
|
||||||
userData.repositoriesContributedTo.totalCount,
|
userData.repositoriesContributedTo.totalCount,
|
||||||
|
languages.size
|
||||||
)
|
)
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
53
src/icons.ts
53
src/icons.ts
|
|
@ -1,11 +1,14 @@
|
||||||
import { RANK } from "./utils.ts";
|
import { RANK } from "./utils.ts";
|
||||||
|
|
||||||
const goldColor = "#FAD200";
|
const goldColor = "#FAD200";
|
||||||
|
const goldShadowColor = "#C8A090";
|
||||||
const goldTextColor = "#886000";
|
const goldTextColor = "#886000";
|
||||||
const silverColor = "#B0B0B0";
|
const silverColor = "#B0B0B0";
|
||||||
|
const sliverShadowColor = "#9090C0";
|
||||||
const silverTextColor = "#505050";
|
const silverTextColor = "#505050";
|
||||||
const bronzeColor = "#816D46";
|
const bronzeColor = "#A18D66";
|
||||||
const bronzeTextColor = "#614D26";
|
const bronzeShadowColor = "#816D96";
|
||||||
|
const bronzeTextColor = "#412D06";
|
||||||
const leafIcon =
|
const leafIcon =
|
||||||
`<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="90pt" height="90pt" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet">
|
`<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="90pt" height="90pt" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet">
|
||||||
<metadata>
|
<metadata>
|
||||||
|
|
@ -30,7 +33,11 @@ Created by potrace 1.15, written by Peter Selinger 2001-2017
|
||||||
</g>
|
</g>
|
||||||
</svg>`;
|
</svg>`;
|
||||||
|
|
||||||
export const getNextRankBar = (title: string, color: string, percentage: number): string => {
|
export const getNextRankBar = (
|
||||||
|
title: string,
|
||||||
|
color: string,
|
||||||
|
percentage: number,
|
||||||
|
): string => {
|
||||||
const maxWidht = 80;
|
const maxWidht = 80;
|
||||||
return `
|
return `
|
||||||
<style>
|
<style>
|
||||||
|
|
@ -93,31 +100,61 @@ export const getTrophyIcon = (rank = RANK.UNKNOWN) => {
|
||||||
let color = "currentColor";
|
let color = "currentColor";
|
||||||
let rankColor = "#333";
|
let rankColor = "#333";
|
||||||
let backgroundIcon = "";
|
let backgroundIcon = "";
|
||||||
if (rank.slice(0, 1) === RANK.S) {
|
let gradationColor = "";
|
||||||
|
if (rank === RANK.SECRET) {
|
||||||
|
rankColor = "fuchsia";
|
||||||
|
gradationColor = `
|
||||||
|
<stop offset="0%" stop-color="red"/>
|
||||||
|
<stop offset="50%" stop-color="fuchsia"/>
|
||||||
|
<stop offset="100%" stop-color="blue"/>
|
||||||
|
`;
|
||||||
|
} else if (rank.slice(0, 1) === RANK.S) {
|
||||||
color = goldColor;
|
color = goldColor;
|
||||||
rankColor = goldTextColor;
|
rankColor = goldTextColor;
|
||||||
backgroundIcon = leafIcon;
|
backgroundIcon = leafIcon;
|
||||||
|
gradationColor = `
|
||||||
|
<stop offset="0%" stop-color="${color}"/>
|
||||||
|
<stop offset="70%" stop-color="${color}"/>
|
||||||
|
<stop offset="100%" stop-color="${goldShadowColor}"/>
|
||||||
|
`;
|
||||||
} else if (rank.slice(0, 1) === RANK.A) {
|
} else if (rank.slice(0, 1) === RANK.A) {
|
||||||
color = silverColor;
|
color = silverColor;
|
||||||
rankColor = silverTextColor;
|
rankColor = silverTextColor;
|
||||||
backgroundIcon = leafIcon;
|
backgroundIcon = leafIcon;
|
||||||
|
gradationColor = `
|
||||||
|
<stop offset="0%" stop-color="${color}"/>
|
||||||
|
<stop offset="70%" stop-color="${color}"/>
|
||||||
|
<stop offset="100%" stop-color="${sliverShadowColor}"/>
|
||||||
|
`;
|
||||||
} else if (rank === RANK.B) {
|
} else if (rank === RANK.B) {
|
||||||
color = bronzeColor;
|
color = bronzeColor;
|
||||||
rankColor = bronzeTextColor;
|
rankColor = bronzeTextColor;
|
||||||
|
gradationColor = `
|
||||||
|
<stop offset="0%" stop-color="${color}"/>
|
||||||
|
<stop offset="70%" stop-color="${color}"/>
|
||||||
|
<stop offset="100%" stop-color="${bronzeShadowColor}"/>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
const icon = `
|
const icon = `
|
||||||
<path d="M3 1h10c-.495 3.467-.5 10-5 10S3.495 4.467 3 1zm0 15a1 1 0 0 1 1-1h8a1 1 0 0 1 1 1H3zm2-1a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1H5z"/>
|
|
||||||
<path fill-rule="evenodd" d="M12.5 3a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm-3 2a3 3 0 1 1 6 0 3 3 0 0 1-6 0zm-6-2a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm-3 2a3 3 0 1 1 6 0 3 3 0 0 1-6 0z"/>
|
|
||||||
<path d="M7 10h2v4H7v-4z"/>
|
<path d="M7 10h2v4H7v-4z"/>
|
||||||
<path d="M10 11c0 .552-.895 1-2 1s-2-.448-2-1 .895-1 2-1 2 .448 2 1z"/>
|
<path d="M10 11c0 .552-.895 1-2 1s-2-.448-2-1 .895-1 2-1 2 .448 2 1z"/>
|
||||||
|
<path fill-rule="evenodd" d="M12.5 3a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm-3 2a3 3 0 1 1 6 0 3 3 0 0 1-6 0zm-6-2a2 2 0 1 0 0 4 2 2 0 0 0 0-4zm-3 2a3 3 0 1 1 6 0 3 3 0 0 1-6 0z"/>
|
||||||
|
<path d="M3 1h10c-.495 3.467-.5 10-5 10S3.495 4.467 3 1zm0 15a1 1 0 0 1 1-1h8a1 1 0 0 1 1 1H3zm2-1a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1H5z"/>
|
||||||
<circle cx="8" cy="6" r="4" fill="#fff" />
|
<circle cx="8" cy="6" r="4" fill="#fff" />
|
||||||
<text x="6" y="8" font-family="Courier, Monospace" font-size="7" fill="${rankColor}">${rank.slice(0, 1)}</text>
|
<text x="6" y="8" font-family="Courier, Monospace" font-size="7" fill="${rankColor}">${
|
||||||
|
rank.slice(0, 1)
|
||||||
|
}</text>
|
||||||
`;
|
`;
|
||||||
const optionRankIcon = getSmallTrophyIcon(icon, color, rank.length - 1);
|
const optionRankIcon = getSmallTrophyIcon(icon, color, rank.length - 1);
|
||||||
return `
|
return `
|
||||||
${backgroundIcon}
|
${backgroundIcon}
|
||||||
${optionRankIcon}
|
${optionRankIcon}
|
||||||
<svg x="28" y="20" width="100" height="100" viewBox="0 0 30 30" class="bi bi-trophy" fill="${color}" xmlns="http://www.w3.org/2000/svg">
|
<defs>
|
||||||
|
<linearGradient id="${rank}" gradientTransform="rotate(45)">
|
||||||
|
${gradationColor}
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
<svg x="28" y="20" width="100" height="100" viewBox="0 0 30 30" fill="url(#${rank})" xmlns="http://www.w3.org/2000/svg">
|
||||||
${icon}
|
${icon}
|
||||||
</svg>
|
</svg>
|
||||||
`;
|
`;
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ export class Trophy {
|
||||||
render(x = 0, y = 0, panelSize = CONSTANTS.DEFAULT_PANEL_SIZE): string {
|
render(x = 0, y = 0, panelSize = CONSTANTS.DEFAULT_PANEL_SIZE): string {
|
||||||
const nextRankBar = getNextRankBar(
|
const nextRankBar = getNextRankBar(
|
||||||
this.title,
|
this.title,
|
||||||
"#0336A6",
|
"#0366d6",
|
||||||
this.calculateNextRankPercentage(),
|
this.calculateNextRankPercentage(),
|
||||||
);
|
);
|
||||||
return `
|
return `
|
||||||
|
|
@ -96,7 +96,7 @@ export class MultipleLangTrophy extends Trophy{
|
||||||
new RankCondition(
|
new RankCondition(
|
||||||
RANK.SECRET,
|
RANK.SECRET,
|
||||||
"Rainbow Lang User",
|
"Rainbow Lang User",
|
||||||
7,
|
10,
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
super(score, rankConditions);
|
super(score, rankConditions);
|
||||||
|
|
@ -357,12 +357,12 @@ export class TotalRepositoryTrophy extends Trophy {
|
||||||
new RankCondition(
|
new RankCondition(
|
||||||
RANK.SSS,
|
RANK.SSS,
|
||||||
"God Repo Creator",
|
"God Repo Creator",
|
||||||
200,
|
100,
|
||||||
),
|
),
|
||||||
new RankCondition(
|
new RankCondition(
|
||||||
RANK.SS,
|
RANK.SS,
|
||||||
"Deep Repo Creator",
|
"Deep Repo Creator",
|
||||||
100,
|
90,
|
||||||
),
|
),
|
||||||
new RankCondition(
|
new RankCondition(
|
||||||
RANK.S,
|
RANK.S,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue