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,
|
||||
TotalPullRequestTrophy,
|
||||
TotalRepositoryTrophy,
|
||||
MultipleLangTrophy
|
||||
} from "./trophies.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 {
|
||||
private width = 0;
|
||||
|
|
@ -30,8 +31,12 @@ export class Card {
|
|||
new TotalIssueTrophy(userInfo.totalIssues),
|
||||
new TotalPullRequestTrophy(userInfo.totalPullRequests),
|
||||
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
||||
new MultipleLangTrophy(userInfo.languageCount),
|
||||
);
|
||||
|
||||
// Filter by hidden
|
||||
trophyList = trophyList.filter((trophy) => !trophy.hidden || trophy.rank !== RANK.UNKNOWN);
|
||||
|
||||
// Filter by titles
|
||||
if (this.titles.length != 0) {
|
||||
trophyList = trophyList.filter((trophy) => this.titles.includes(trophy.title))
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export class UserInfo {
|
|||
public totalStargazers: number,
|
||||
public totalRepositories: 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}) {
|
||||
totalCount
|
||||
nodes {
|
||||
languages(first: 1, orderBy: {direction:DESC, field: SIZE}) {
|
||||
nodes {
|
||||
name
|
||||
}
|
||||
}
|
||||
stargazers {
|
||||
totalCount
|
||||
}
|
||||
|
|
@ -63,6 +69,13 @@ export class GithubAPIClient {
|
|||
const totalStargazers = userData.repositories.nodes.reduce((prev: number, node: any) => {
|
||||
return prev + node.stargazers.totalCount;
|
||||
}, 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(
|
||||
totalCommits,
|
||||
userData.followers.totalCount,
|
||||
|
|
@ -71,6 +84,7 @@ export class GithubAPIClient {
|
|||
totalStargazers,
|
||||
userData.repositories.totalCount,
|
||||
userData.repositoriesContributedTo.totalCount,
|
||||
languages.size
|
||||
)
|
||||
return userInfo;
|
||||
}
|
||||
|
|
|
|||
53
src/icons.ts
53
src/icons.ts
|
|
@ -1,11 +1,14 @@
|
|||
import { RANK } from "./utils.ts";
|
||||
|
||||
const goldColor = "#FAD200";
|
||||
const goldShadowColor = "#C8A090";
|
||||
const goldTextColor = "#886000";
|
||||
const silverColor = "#B0B0B0";
|
||||
const sliverShadowColor = "#9090C0";
|
||||
const silverTextColor = "#505050";
|
||||
const bronzeColor = "#816D46";
|
||||
const bronzeTextColor = "#614D26";
|
||||
const bronzeColor = "#A18D66";
|
||||
const bronzeShadowColor = "#816D96";
|
||||
const bronzeTextColor = "#412D06";
|
||||
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">
|
||||
<metadata>
|
||||
|
|
@ -30,7 +33,11 @@ Created by potrace 1.15, written by Peter Selinger 2001-2017
|
|||
</g>
|
||||
</svg>`;
|
||||
|
||||
export const getNextRankBar = (title: string, color: string, percentage: number): string => {
|
||||
export const getNextRankBar = (
|
||||
title: string,
|
||||
color: string,
|
||||
percentage: number,
|
||||
): string => {
|
||||
const maxWidht = 80;
|
||||
return `
|
||||
<style>
|
||||
|
|
@ -93,31 +100,61 @@ export const getTrophyIcon = (rank = RANK.UNKNOWN) => {
|
|||
let color = "currentColor";
|
||||
let rankColor = "#333";
|
||||
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;
|
||||
rankColor = goldTextColor;
|
||||
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) {
|
||||
color = silverColor;
|
||||
rankColor = silverTextColor;
|
||||
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) {
|
||||
color = bronzeColor;
|
||||
rankColor = bronzeTextColor;
|
||||
gradationColor = `
|
||||
<stop offset="0%" stop-color="${color}"/>
|
||||
<stop offset="70%" stop-color="${color}"/>
|
||||
<stop offset="100%" stop-color="${bronzeShadowColor}"/>
|
||||
`;
|
||||
}
|
||||
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="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" />
|
||||
<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);
|
||||
return `
|
||||
${backgroundIcon}
|
||||
${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}
|
||||
</svg>
|
||||
`;
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ export class Trophy {
|
|||
render(x = 0, y = 0, panelSize = CONSTANTS.DEFAULT_PANEL_SIZE): string {
|
||||
const nextRankBar = getNextRankBar(
|
||||
this.title,
|
||||
"#0336A6",
|
||||
"#0366d6",
|
||||
this.calculateNextRankPercentage(),
|
||||
);
|
||||
return `
|
||||
|
|
@ -96,7 +96,7 @@ export class MultipleLangTrophy extends Trophy{
|
|||
new RankCondition(
|
||||
RANK.SECRET,
|
||||
"Rainbow Lang User",
|
||||
7,
|
||||
10,
|
||||
),
|
||||
];
|
||||
super(score, rankConditions);
|
||||
|
|
@ -357,12 +357,12 @@ export class TotalRepositoryTrophy extends Trophy {
|
|||
new RankCondition(
|
||||
RANK.SSS,
|
||||
"God Repo Creator",
|
||||
200,
|
||||
100,
|
||||
),
|
||||
new RankCondition(
|
||||
RANK.SS,
|
||||
"Deep Repo Creator",
|
||||
100,
|
||||
90,
|
||||
),
|
||||
new RankCondition(
|
||||
RANK.S,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue