Compare commits

..
Author SHA1 Message Date
Zohan Subhash e5ba3238ab Update readme.md 2023-02-18 12:25:52 +05:30
Zohan Subhash f4e731ee09 Delete top-langs.js 2023-02-18 12:23:14 +05:30
Zohan Subhash 6f07b51c00 Delete pin.js 2023-02-18 12:23:10 +05:30
Zohan Subhash 6e0522cdd9 Delete index.js 2023-02-18 12:23:06 +05:30
Zohan Subhash 4ce744f7b5 Merge pull request #2527 from Zo-Bro-23/custom-cards
Transfer branch from my fork to main repo
2023-02-18 12:22:23 +05:30
Zohan Subhash 3565f25c46 Merge branch 'zo/custom-cards' into custom-cards 2023-02-18 12:21:53 +05:30
Zohan Subhash a5114d12d0 Update top-langs.js 2023-01-26 16:52:36 +05:30
Zohan Subhash 20914797b0 Disable cache 2023-01-26 16:52:18 +05:30
Zohan Subhash 11cb8dffc1 Disable cache 2023-01-26 16:51:40 +05:30
Zohan Subhash a885425b52 Update readme.md 2023-01-17 17:07:41 +05:30
Zohan Subhash 017e3ba180 Update readme.md 2023-01-17 16:54:56 +05:30
Zohan Subhash 03465922b0 Update readme.md 2023-01-17 16:49:19 +05:30
Zohan Subhash 9829ab990d Update readme.md 2023-01-17 16:47:22 +05:30
Zohan Subhash 6243c702c3 Update top-langs.js 2023-01-17 16:33:50 +05:30
Zohan Subhash 97cef21e4e Update repo-card.js 2023-01-17 16:09:08 +05:30
Zohan Subhash 55a3cecd49 Update repo-card.js 2023-01-17 16:07:42 +05:30
Zohan Subhash e245941e5a Update repo-card.js 2023-01-17 16:05:24 +05:30
Zohan Subhash 04ed2bdd3f Update repo-card.js 2023-01-17 16:02:23 +05:30
Zohan Subhash c33f3f617a Update repo-card.js 2023-01-17 15:59:11 +05:30
Zohan Subhash 589badc483 Update pin.js 2023-01-17 15:57:59 +05:30
Zohan Subhash 05b611ad58 Update pin.js 2023-01-17 15:55:42 +05:30
Zohan Subhash bf0a15f94f Update pin.js 2023-01-17 15:52:46 +05:30
Zohan Subhash b8425d36c8 Update repo-card.js 2023-01-17 15:51:33 +05:30
Zohan Subhash 866e509d07 Create pin.js 2023-01-17 15:49:21 +05:30
Zohan Subhash c1e2858330 Update repo-card.js 2023-01-17 15:47:39 +05:30
Zohan Subhash 01f726c316 Update repo-card.js 2023-01-17 15:43:37 +05:30
Zohan Subhash 2770161e33 Update top-languages-card.js 2023-01-16 16:40:12 +05:30
Zohan Subhash b320054e90 Update top-languages-card.js 2023-01-16 16:38:33 +05:30
Zohan Subhash 5675ce77b1 Update top-langs.js 2023-01-16 16:37:25 +05:30
Zohan Subhash 27029cd565 Update top-languages-card.js 2023-01-16 16:35:32 +05:30
Zohan Subhash df42981d34 Update top-langs.js 2023-01-16 16:34:14 +05:30
Zohan Subhash 4ecebbca94 Update top-languages-card.js 2023-01-16 16:28:51 +05:30
Zohan Subhash 80e6d0acc5 Update top-languages-card.js 2023-01-16 16:26:44 +05:30
Zohan Subhash 0adcb158f9 Update top-languages-card.js 2023-01-16 16:21:00 +05:30
Zohan Subhash 2cb4861b24 Update top-langs.js 2023-01-16 16:14:59 +05:30
Zohan Subhash 3cebd8907b Update top-languages-card.js 2023-01-16 16:14:14 +05:30
Zohan Subhash 42503cf90c Update top-langs.js 2023-01-16 15:43:03 +05:30
Zohan Subhash 2466713261 Update top-langs.js 2023-01-16 15:37:18 +05:30
Zohan Subhash 9c08efedbf Update top-langs.js 2023-01-16 15:37:02 +05:30
Zohan Subhash af36d0b2e1 Update top-langs.js 2023-01-16 15:32:22 +05:30
Zohan Subhash 1689ca6feb Update top-langs.js 2023-01-16 15:31:04 +05:30
Zohan Subhash 642d63d4f0 Update top-langs.js 2023-01-16 15:23:20 +05:30
Zohan Subhash 2a1d255e45 Update top-langs.js 2023-01-16 15:12:05 +05:30
Zohan Subhash 114225e72e Update top-langs.js 2023-01-15 16:04:55 +05:30
Zohan Subhash cc558e4d7c Update top-langs.js 2023-01-15 16:01:17 +05:30
Zohan Subhash 6738c6db5f Update top-langs.js 2023-01-15 15:57:10 +05:30
Zohan Subhash ede2574b13 Update top-langs.js 2023-01-15 15:55:48 +05:30
Zohan Subhash c6ca64551e Update top-langs.js 2023-01-15 15:49:01 +05:30
Zohan Subhash 5448a611ba Create top-langs.js 2023-01-15 15:47:18 +05:30
Zohan Subhash 22aa6887f9 Update index.js 2023-01-15 15:43:28 +05:30
Zohan Subhash ffd927af6d Update top-languages-card.js 2023-01-15 15:39:54 +05:30
Zohan Subhash f02186908d Update stats-card.js 2023-01-14 11:59:30 +05:30
Zohan Subhash 8f63eaeef9 Update stats-card.js 2023-01-14 11:57:53 +05:30
Zohan Subhash 70b0d025f8 Update index.js 2023-01-14 11:54:14 +05:30
Zohan Subhash dc95c44c22 Update index.js 2023-01-14 11:52:06 +05:30
Zohan Subhash adbc7a36c9 Update stats-card.js 2023-01-14 11:51:44 +05:30
Zohan Subhash 1651db55ec Update index.js 2023-01-14 11:47:12 +05:30
Zohan Subhash e40f214a76 Create index.js 2023-01-14 11:46:26 +05:30
Zohan Subhash 88aa6fe30c Update stats-card.js 2023-01-14 11:44:44 +05:30
Zohan Subhash ad731cdfcb Update stats-card.js 2023-01-14 11:17:00 +05:30
Zohan Subhash 237942c234 Update index.js 2023-01-14 10:57:44 +05:30
Zohan Subhash d505580a4f Update index.js 2023-01-14 10:55:44 +05:30
Zohan Subhash 4dbab9a2a3 Update stats-card.js 2023-01-14 10:55:12 +05:30
Zohan Subhash d8af18e465 Update stats-card.js 2023-01-14 10:52:26 +05:30
Zohan Subhash 1af63921b5 Update index.js 2023-01-14 10:46:44 +05:30
Zohan Subhash 9ff83e0855 Update index.js 2023-01-14 10:41:30 +05:30
Zohan Subhash 6349ec8f32 Update stats-card.js 2023-01-14 10:40:56 +05:30
Zohan Subhash 31f2920c09 Update vercel.json 2023-01-14 08:02:31 +05:30
Zohan Subhash 19cf691983 Update index.js 2023-01-13 18:52:41 +05:30
Zohan Subhash 36e838da62 Update stats-card.js 2023-01-13 18:48:32 +05:30
18 changed files with 186 additions and 377 deletions
-1
View File
@@ -1,4 +1,3 @@
themes: themes/index.js
doc-translation: docs/*
card-i18n: src/translations.js
documentation: readme.md
-4
View File
@@ -23,10 +23,6 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: npm
# Fix the unsafe repo error which was introduced by the CVE-2022-24765 git patches.
- name: Fix unsafe repo error
run: git config --global --add safe.directory ${{ github.workspace }}
- name: npm install, generate readme
run: |
npm ci
-2
View File
@@ -10,5 +10,3 @@ vercel_token
# IDE
.vscode
*.code-workspace
.vercel
+2 -2
View File
@@ -2,11 +2,11 @@
* @file Contains a simple cloud function that can be used to check which PATs are no
* longer working. It returns a list of valid PATs, expired PATs and PATs with errors.
*
* @description This function is currently rate limited to 1 request per 5 minutes.
* @description This function is currently rate limited to 1 request per 10 minutes.
*/
import { logger, request, dateDiff } from "../../src/common/utils.js";
export const RATE_LIMIT_SECONDS = 60 * 5; // 1 request per 5 minutes
export const RATE_LIMIT_SECONDS = 60 * 5; // 1 request per 10 minutes
/**
* Simple uptime check fetcher for the PATs.
+2 -2
View File
@@ -2,13 +2,13 @@
* @file Contains a simple cloud function that can be used to check if the PATs are still
* functional.
*
* @description This function is currently rate limited to 1 request per 5 minutes.
* @description This function is currently rate limited to 1 request per 10 minutes.
*/
import retryer from "../../src/common/retryer.js";
import { logger, request } from "../../src/common/utils.js";
export const RATE_LIMIT_SECONDS = 60 * 5; // 1 request per 5 minutes
export const RATE_LIMIT_SECONDS = 60 * 10; // 1 request per 10 minutes
/**
* Simple uptime check fetcher for the PATs.
-15
View File
@@ -1,15 +0,0 @@
import statsCard from "./api/index.js";
import repoCard from "./api/pin.js";
import langCard from "./api/top-langs.js";
import wakatimeCard from "./api/wakatime.js";
import express from "express";
import dotenv from "dotenv";
dotenv.config();
const app = express();
app.listen(process.env.port || 9000);
app.get("/", statsCard);
app.get("/pin", repoCard);
app.get("/top-langs", langCard);
app.get("/wakatime", wakatimeCard);
+3 -24
View File
@@ -92,9 +92,7 @@ Visit <https://indiafightscorona.giveindia.org> and make a small donation to hel
- [Repo Card Exclusive Options](#repo-card-exclusive-options)
- [Language Card Exclusive Options](#language-card-exclusive-options)
- [Wakatime Card Exclusive Option](#wakatime-card-exclusive-options)
- [Deploy Yourself](#deploy-on-your-own)
- [On Vercel](#on-vercel)
- [On other platforms](#on-other-platforms)
- [Deploy Yourself](#deploy-on-your-own-vercel-instance)
- [Keep your fork up to date](#keep-your-fork-up-to-date)
# GitHub Stats Card
@@ -135,7 +133,7 @@ You can add the count of all your private contributions to the total commits cou
### Showing icons
To enable icons, you can pass `&show_icons=true` in the query param, like so:
To enable icons, you can pass `show_icons=true` in the query param, like so:
```md
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true)
@@ -511,9 +509,7 @@ By default, GitHub does not lay out the cards side by side. To do that, you can
</a>
```
## Deploy on your own
### On Vercel
## Deploy on your own Vercel instance
#### :film_projector: [Check Out Step By Step Video Tutorial By @codeSTACKr](https://youtu.be/n6d4KHSKqGk?t=107)
@@ -550,23 +546,6 @@ Since the GitHub API only allows 5k requests per hour, my `https://github-readme
</details>
### On other platforms
> **Warning**
> This way of using GRS is not officially supported and was added to cater to some particular use cases where Vercel could not be used (e.g. #2341). The support for this method, therefore, is limited.
<details>
<summary><b>:hammer_and_wrench: Step-by-step guide for deploying on other platforms</b></summary>
1. Fork or clone this repo as per your needs
2. Add `express` to the dependencies section of `package.json`
https://github.com/anuraghazra/github-readme-stats/blob/ba7c2f8b55eac8452e479c8bd38b044d204d0424/package.json#L54-L61
3. Run `npm i` if needed (initial setup)
4. Run `node express.js` to start the server, or set the entry point to `express.js` in `package.json` if you're deploying on a managed service
https://github.com/anuraghazra/github-readme-stats/blob/ba7c2f8b55eac8452e479c8bd38b044d204d0424/package.json#L11
5. You're done 🎉
</details>
### Keep your fork up to date
You can keep your fork, and thus your private Vercel instance up to date with the upstream using GitHubs' [Sync Fork button](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork). You can also use the [pull](https://github.com/wei/pull) package created by [@wei](https://github.com/wei) to automate this process.
+60 -128
View File
@@ -43,23 +43,6 @@ const ACCEPTED_COLOR_PROPS = Object.keys(COLOR_PROPS);
const REQUIRED_COLOR_PROPS = ACCEPTED_COLOR_PROPS.slice(0, 4);
const INVALID_REVIEW_COMMENT = (commentUrl) =>
`Some themes are invalid. See the [Automated Theme Preview](${commentUrl}) comment above for more information.`;
var OCTOKIT;
var OWNER;
var REPO;
var PULL_REQUEST_ID;
/**
* Incorrect JSON format error.
* @extends Error
* @param {string} message Error message.
* @returns {Error} IncorrectJsonFormatError.
*/
class IncorrectJsonFormatError extends Error {
constructor(message) {
super(message);
this.name = "IncorrectJsonFormatError";
}
}
/**
* Retrieve PR number from the event payload.
@@ -143,36 +126,15 @@ const findComment = async (octokit, issueNumber, owner, repo, commenter) => {
* Create or update the preview comment.
*
* @param {Object} octokit Octokit instance.
* @param {number} issueNumber Issue number.
* @param {Object} repo Repository name.
* @param {Object} owner Owner of the repository.
* @param {number} commentId Comment ID.
* @param {string} body Comment body.
* @param {Object} props Comment properties.
* @return {string} The comment URL.
*/
const upsertComment = async (
octokit,
issueNumber,
repo,
owner,
commentId,
body,
) => {
const upsertComment = async (octokit, props) => {
let resp;
if (commentId !== undefined) {
resp = await octokit.issues.updateComment({
owner,
repo,
comment_id: commentId,
body,
});
if (props.comment_id !== undefined) {
resp = await octokit.issues.updateComment(props);
} else {
resp = await octokit.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body,
});
resp = await octokit.issues.createComment(props);
}
return resp.data.html_url;
};
@@ -307,38 +269,22 @@ const parseJSON = (json) => {
if (typeof parsedJson === "object") {
return parsedJson;
} else {
throw new IncorrectJsonFormatError(
"PR diff is not a valid theme JSON object.",
);
throw new Error("PR diff is not a valid theme JSON object.");
}
} catch (error) {
// Remove trailing commas (if any).
let parsedJson = json.replace(/(,\s*})/g, "}");
// Remove JS comments (if any).
parsedJson = parsedJson.replace(/\/\/[A-z\s]*\s/g, "");
// Fix incorrect open bracket (if any).
const splitJson = parsedJson
let parsedJson = json
.split(/([\s\r\s]*}[\s\r\s]*,[\s\r\s]*)(?=[\w"-]+:)/)
.filter((x) => typeof x !== "string" || !!x.trim()); // Split json into array of strings and objects.
if (splitJson[0].replace(/\s+/g, "") === "},") {
splitJson[0] = "},";
if (!/\s*}\s*,?\s*$/.test(splitJson[1])) {
splitJson.push(splitJson.shift());
.filter((x) => typeof x !== "string" || !!x.trim());
if (parsedJson[0].replace(/\s+/g, "") === "},") {
parsedJson[0] = "},";
if (!/\s*}\s*,?\s*$/.test(parsedJson[1])) {
parsedJson.push(parsedJson.shift());
} else {
splitJson.shift();
parsedJson.shift();
}
parsedJson = splitJson.join("");
}
// Try to parse the fixed json.
try {
return Hjson.parse(parsedJson);
} catch (error) {
throw new IncorrectJsonFormatError(
`Theme JSON file could not be parsed: ${error.message}`,
);
return Hjson.parse(parsedJson.join(""));
} else {
throw error;
}
}
};
@@ -352,13 +298,12 @@ const themeNameAlreadyExists = (name) => {
return themes[name] !== undefined;
};
const DRY_RUN = process.env.DRY_RUN === "true" || false;
/**
* Main function.
*/
export const run = async () => {
export const run = async (prNumber) => {
try {
const dryRun = process.env.DRY_RUN === "true" || false;
debug("Retrieve action information from context...");
debug(`Context: ${inspect(github.context)}`);
let commentBody = `
@@ -366,50 +311,40 @@ export const run = async () => {
\r${THEME_CONTRIB_GUIDELINESS}
`;
const ccc = new ColorContrastChecker();
OCTOKIT = github.getOctokit(getGithubToken());
PULL_REQUEST_ID = getPrNumber();
const { owner, repo } = getRepoInfo(github.context);
OWNER = owner;
REPO = repo;
const octokit = github.getOctokit(getGithubToken());
const pullRequestId = prNumber ? prNumber : getPrNumber();
const commenter = getCommenter();
PULL_REQUEST_ID = getPrNumber();
debug(`Owner: ${OWNER}`);
debug(`Repo: ${REPO}`);
const { owner, repo } = getRepoInfo(github.context);
debug(`Owner: ${owner}`);
debug(`Repo: ${repo}`);
debug(`Commenter: ${commenter}`);
// Retrieve the PR diff and preview-theme comment.
debug("Retrieve PR diff...");
const res = await OCTOKIT.pulls.get({
owner: OWNER,
repo: REPO,
pull_number: PULL_REQUEST_ID,
const res = await octokit.pulls.get({
owner,
repo,
pull_number: pullRequestId,
mediaType: {
format: "diff",
},
});
debug("Retrieve preview-theme comment...");
const comment = await findComment(
OCTOKIT,
PULL_REQUEST_ID,
OWNER,
REPO,
octokit,
pullRequestId,
owner,
repo,
commenter,
);
// Retrieve theme changes from the PR diff.
debug("Retrieve themes...");
const diff = parse(res.data);
// Retrieve all theme changes from the PR diff and convert to JSON.
debug("Retrieve theme changes...");
const content = diff
.find((file) => file.to === "themes/index.js")
.chunks.map((chunk) =>
chunk.changes
.filter((c) => c.type === "add")
.map((c) => c.content.replace("+", ""))
.join(""),
)
.chunks[0].changes.filter((c) => c.type === "add")
.map((c) => c.content.replace("+", ""))
.join("");
const themeObject = parseJSON(content);
if (
@@ -578,15 +513,14 @@ export const run = async () => {
// Create or update theme-preview comment.
debug("Create or update theme-preview comment...");
let comment_url;
if (!DRY_RUN) {
comment_url = await upsertComment(
OCTOKIT,
PULL_REQUEST_ID,
REPO,
OWNER,
comment?.id,
commentBody,
);
if (!dryRun) {
comment_url = await upsertComment(octokit, {
comment_id: comment?.id,
issue_number: pullRequestId,
owner,
repo,
body: commentBody,
});
} else {
info(`DRY_RUN: Comment body: ${commentBody}`);
comment_url = "";
@@ -601,20 +535,20 @@ export const run = async () => {
const reviewReason = themesValid
? undefined
: INVALID_REVIEW_COMMENT(comment_url);
if (!DRY_RUN) {
if (!dryRun) {
await addReview(
OCTOKIT,
PULL_REQUEST_ID,
OWNER,
REPO,
octokit,
pullRequestId,
owner,
repo,
reviewState,
reviewReason,
);
await addRemoveLabel(
OCTOKIT,
PULL_REQUEST_ID,
OWNER,
REPO,
octokit,
pullRequestId,
owner,
repo,
"invalid",
!themesValid,
);
@@ -624,22 +558,20 @@ export const run = async () => {
}
} catch (error) {
debug("Set review state to `REQUEST_CHANGES` and add `invalid` label...");
if (!DRY_RUN) {
if (!dryRun) {
await addReview(
OCTOKIT,
PULL_REQUEST_ID,
OWNER,
REPO,
octokit,
pullRequestId,
owner,
repo,
"REQUEST_CHANGES",
"**Something went wrong in the theme preview action:** `" +
error.message +
"`",
error.message,
);
await addRemoveLabel(
OCTOKIT,
PULL_REQUEST_ID,
OWNER,
REPO,
octokit,
pullRequestId,
owner,
repo,
"invalid",
true,
);
-1
View File
@@ -6,7 +6,6 @@ export BRANCH_NAME=updated-theme-readme
git --version
git config --global user.email "no-reply@githubreadmestats.com"
git config --global user.name "GitHub Readme Stats Bot"
git config --global --add safe.directory ${GITHUB_WORKSPACE}
git branch -d $BRANCH_NAME || true
git checkout -b $BRANCH_NAME
git add --all
+51 -35
View File
@@ -87,16 +87,6 @@ const iconWithLabel = (icon, label, testid) => {
* @returns {string} Repository card SVG object.
*/
const renderRepoCard = (repo, options = {}) => {
const {
name,
nameWithOwner,
description,
primaryLanguage,
isArchived,
isTemplate,
starCount,
forkCount,
} = repo;
const {
hide_border = false,
title_color,
@@ -109,6 +99,42 @@ const renderRepoCard = (repo, options = {}) => {
border_color,
locale,
} = options;
const i18n = new I18n({
locale,
translations: repoCardLocales,
});
const colors = getCardColors({
title_color,
icon_color,
text_color,
bg_color,
border_color,
theme,
});
const {
name,
nameWithOwner,
description,
primaryLanguage,
isArchived,
isTemplate,
starCount,
forkCount,
} = repo;
const highlight = repo.highlight
? // @ts-ignore
getBadgeSVG(repo.highlight, colors.textColor)
: isTemplate
? // @ts-ignore
getBadgeSVG(i18n.t("repocard.template"), colors.textColor)
: isArchived
? // @ts-ignore
getBadgeSVG(i18n.t("repocard.archived"), colors.textColor)
: ""
const lineHeight = 10;
const header = show_owner ? nameWithOwner : name;
@@ -125,27 +151,25 @@ const renderRepoCard = (repo, options = {}) => {
const height =
(descriptionLines > 1 ? 120 : 110) + descriptionLines * lineHeight;
const i18n = new I18n({
locale,
translations: repoCardLocales,
});
// returns theme based colors with proper overrides and defaults
const colors = getCardColors({
title_color,
icon_color,
text_color,
bg_color,
border_color,
theme,
});
const svgLanguage = primaryLanguage
? createLanguageNode(langName, langColor)
: "";
const totalStars = kFormatter(starCount);
const totalForks = kFormatter(forkCount);
let totalStars
let totalForks
if (isNaN(starCount)) {
totalStars = starCount;
} else {
totalStars = kFormatter(starCount);
}
if (isNaN(forkCount)) {
totalForks = forkCount;
} else {
totalForks = kFormatter(forkCount);
}
const svgStars = iconWithLabel(icons.star, totalStars, "stargazers");
const svgForks = iconWithLabel(icons.fork, totalForks, "forkcount");
@@ -180,15 +204,7 @@ const renderRepoCard = (repo, options = {}) => {
`);
return card.render(`
${
isTemplate
? // @ts-ignore
getBadgeSVG(i18n.t("repocard.template"), colors.textColor)
: isArchived
? // @ts-ignore
getBadgeSVG(i18n.t("repocard.archived"), colors.textColor)
: ""
}
${highlight}
<text class="description" x="25" y="-5">
${descriptionSvg}
+44 -32
View File
@@ -40,7 +40,12 @@ const createTextNode = ({
shiftValuePos,
bold,
}) => {
const kValue = kFormatter(value);
let kValue
if (isNaN(value)) {
kValue = value;
} else {
kValue = kFormatter(value);
}
const staggerDelay = (index + 3) * 150;
const labelOffset = showIcons ? `x="25"` : "";
@@ -75,15 +80,6 @@ const createTextNode = ({
* @returns {string} The stats card SVG object.
*/
const renderStatsCard = (stats = {}, options = { hide: [] }) => {
const {
name,
totalStars,
totalCommits,
totalIssues,
totalPRs,
contributedTo,
rank,
} = stats;
const {
hide = [],
show_icons = false,
@@ -106,6 +102,37 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
locale,
disable_animations = false,
} = options;
const name = stats.name || "GitHub User"
const apostrophe = ["x", "s"].includes(name.slice(-1).toLocaleLowerCase())
? ""
: "s";
const i18n = new I18n({
locale,
translations: statCardLocales({ name, apostrophe }),
});
const {
totalStars = "2018",
totalCommits = "29019",
totalIssues = "203",
totalPRs = "127",
contributedTo = "232",
rank = {
level: "S",
score: 10
},
starsTitle = i18n.t("statcard.totalstars"),
commitsTitle = `${i18n.t("statcard.commits")}${
include_all_commits ? "" : ` (${new Date().getFullYear()})`
}`,
issuesTitle = i18n.t("statcard.issues"),
PRsTitle = i18n.t("statcard.prs"),
contribsTitle = i18n.t("statcard.contribs") + " (last year)",
title = i18n.t("statcard.title"),
} = stats;
const lheight = parseInt(String(line_height), 10);
@@ -121,45 +148,35 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
theme,
});
const apostrophe = ["x", "s"].includes(name.slice(-1).toLocaleLowerCase())
? ""
: "s";
const i18n = new I18n({
locale,
translations: statCardLocales({ name, apostrophe }),
});
// Meta data for creating text nodes with createTextNode function
const STATS = {
stars: {
icon: icons.star,
label: i18n.t("statcard.totalstars"),
label: starsTitle,
value: totalStars,
id: "stars",
},
commits: {
icon: icons.commits,
label: `${i18n.t("statcard.commits")}${
include_all_commits ? "" : ` (${new Date().getFullYear()})`
}`,
label: commitsTitle,
value: totalCommits,
id: "commits",
},
prs: {
icon: icons.prs,
label: i18n.t("statcard.prs"),
label: PRsTitle,
value: totalPRs,
id: "prs",
},
issues: {
icon: icons.issues,
label: i18n.t("statcard.issues"),
label: issuesTitle,
value: totalIssues,
id: "issues",
},
contribs: {
icon: icons.contribs,
label: i18n.t("statcard.contribs") + " (last year)",
label: contribsTitle,
value: contributedTo,
id: "contribs",
},
@@ -215,7 +232,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
});
const calculateTextWidth = () => {
return measureText(custom_title ? custom_title : i18n.t("statcard.title"));
return measureText(custom_title ? custom_title : title);
};
/*
@@ -241,7 +258,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
const card = new Card({
customTitle: custom_title,
defaultTitle: i18n.t("statcard.title"),
defaultTitle: title,
width,
height,
border_radius,
@@ -306,11 +323,6 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
const labels = Object.keys(STATS)
.filter((key) => !hide.includes(key))
.map((key) => {
if (key === "commits") {
return `${i18n.t("statcard.commits")} ${
include_all_commits ? "" : `in ${new Date().getFullYear()}`
} : ${totalStars}`;
}
return `${STATS[key].label}: ${STATS[key].value}`;
})
.join(", ");
+15 -11
View File
@@ -13,7 +13,7 @@ import {
import { langCardLocales } from "../translations.js";
const DEFAULT_CARD_WIDTH = 300;
const MIN_CARD_WIDTH = 280;
const MIN_CARD_WIDTH = 230;
const DEFAULT_LANGS_COUNT = 5;
const DEFAULT_LANG_COLOR = "#858585";
const CARD_PADDING = 25;
@@ -47,6 +47,7 @@ const getLongestLang = (arr) =>
* @param {number} props.index Index of the programming language.
* @returns {string} Programming language SVG node.
*/
const createProgressTextNode = ({ width, color, name, progress, index }) => {
const staggerDelay = (index + 3) * 150;
const paddingRight = 95;
@@ -56,7 +57,7 @@ const createProgressTextNode = ({ width, color, name, progress, index }) => {
return `
<g class="stagger" style="animation-delay: ${staggerDelay}ms">
<text data-testid="lang-name" x="2" y="15" class="lang-name">${name}</text>
<text x="${progressTextX}" y="34" class="lang-name">${progress}%</text>
<text x="${progressTextX}" y="34" class="lang-name">${text || `${progress}%`}</text>
${createProgressNode({
x: 0,
y: 25,
@@ -89,7 +90,7 @@ const createCompactLangNode = ({ lang, totalSize, hideProgress, index }) => {
<g class="stagger" style="animation-delay: ${staggerDelay}ms">
<circle cx="5" cy="6" r="5" fill="${color}" />
<text data-testid="lang-name" x="15" y="10" class='lang-name'>
${lang.name} ${hideProgress ? "" : percentage + "%"}
${lang.name} ${hideProgress ? "" : (lang.text || `${percentage}%`)}
</text>
</g>
`;
@@ -126,7 +127,7 @@ const createLanguageTextNode = ({ langs, totalSize, hideProgress }) => {
const percent = ((longestLang.size / totalSize) * 100).toFixed(2);
const minGap = 150;
const maxGap = 20 + measureText(`${longestLang.name} ${percent}%`, 11);
const maxGap = 20 + measureText(`${longestLang.name} ${longestLang.text || `${percent}%`}`, 11);
return flexLayout({
items: layouts,
gap: maxGap < minGap ? minGap : maxGap,
@@ -149,6 +150,7 @@ const renderNormalLayout = (langs, width, totalLanguageSize) => {
name: lang.name,
color: lang.color || DEFAULT_LANG_COLOR,
progress: ((lang.size / totalLanguageSize) * 100).toFixed(2),
text: lang.text,
index,
});
}),
@@ -278,6 +280,12 @@ const useLanguages = (topLangs, hide, langs_count) => {
* @returns {string} Language card SVG object.
*/
const renderTopLanguages = (topLangs, options = {}) => {
const locale = options.locale
const i18n = new I18n({
locale,
translations: langCardLocales,
});
const {
hide_title = false,
hide_border,
@@ -290,18 +298,13 @@ const renderTopLanguages = (topLangs, options = {}) => {
theme,
layout,
custom_title,
locale,
langs_count = DEFAULT_LANGS_COUNT,
border_radius,
border_color,
title = i18n.t("langcard.title"),
disable_animations,
} = options;
const i18n = new I18n({
locale,
translations: langCardLocales,
});
const { langs, totalLanguageSize } = useLanguages(
topLangs,
hide,
@@ -317,6 +320,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
let finalLayout = "";
if (layout === "compact" || hide_progress == true) {
width = width + 50; // padding
height =
calculateCompactLayoutHeight(langs.length) + (hide_progress ? -25 : 0);
@@ -341,7 +345,7 @@ const renderTopLanguages = (topLangs, options = {}) => {
const card = new Card({
customTitle: custom_title,
defaultTitle: i18n.t("langcard.title"),
defaultTitle: title,
width,
height,
border_radius,
+1 -25
View File
@@ -118,7 +118,6 @@ const createTextNode = ({
// @ts-ignore
name: label,
progressBarBackgroundColor,
delay: staggerDelay + 300,
});
return `
@@ -277,12 +276,11 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
} else {
finalLayout = flexLayout({
items: filteredLanguages.length
? filteredLanguages.map((language, index) => {
? filteredLanguages.map((language) => {
return createTextNode({
id: language.name,
label: language.name,
value: language.text,
index: index,
percent: language.percent,
// @ts-ignore
progressBarColor: titleColor,
@@ -323,29 +321,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
card.setCSS(
`
${cssStyles}
@keyframes slideInAnimation {
from {
width: 0;
}
to {
width: calc(100%-100px);
}
}
@keyframes growWidthAnimation {
from {
width: 0;
}
to {
width: 100%;
}
}
.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: ${textColor} }
#rect-mask rect{
animation: slideInAnimation 1s ease-in-out forwards;
}
.lang-progress{
animation: growWidthAnimation 0.6s ease-in-out forwards;
}
`,
);
+2 -10
View File
@@ -79,7 +79,6 @@
"Ceylon": "#dfa535",
"Chapel": "#8dc63f",
"ChucK": "#3f8000",
"Circom": "#707575",
"Cirru": "#ccccff",
"Clarion": "#db901e",
"Clarity": "#5546ff",
@@ -117,7 +116,6 @@
"DirectX 3D File": "#aace60",
"Dockerfile": "#384d54",
"Dogescript": "#cca760",
"Dotenv": "#e5d559",
"Dylan": "#6c616e",
"E": "#ccce35",
"ECL": "#8a1267",
@@ -151,7 +149,7 @@
"Forth": "#341708",
"Fortran": "#4d41b1",
"Fortran Free Form": "#4d41b1",
"FreeBasic": "#141AC9",
"FreeBasic": "#867db1",
"FreeMarker": "#0050b2",
"Frege": "#00cafe",
"Futhark": "#5f021f",
@@ -184,7 +182,6 @@
"Go": "#00ADD8",
"Go Checksums": "#00ADD8",
"Go Module": "#00ADD8",
"Godot Resource": "#355570",
"Golo": "#88562A",
"Gosu": "#82937f",
"Grace": "#615f8b",
@@ -195,7 +192,6 @@
"Groovy": "#4298b8",
"Groovy Server Pages": "#4298b8",
"HAProxy": "#106da9",
"HCL": "#844FBA",
"HLSL": "#aace60",
"HOCON": "#9ff8ee",
"HTML": "#e34c26",
@@ -229,7 +225,6 @@
"Isabelle ROOT": "#FEFE00",
"J": "#9EEDFF",
"JAR Manifest": "#b07219",
"JCL": "#d90e09",
"JFlex": "#DBCA00",
"JSON": "#292929",
"JSON with Comments": "#292929",
@@ -252,11 +247,9 @@
"Jsonnet": "#0064bd",
"Julia": "#a270ba",
"Jupyter Notebook": "#DA5B0B",
"Just": "#384d54",
"KRL": "#28430A",
"Kaitai Struct": "#773b37",
"KakouneScript": "#6f8042",
"KerboScript": "#41adf0",
"KiCad Layout": "#2f4aab",
"KiCad Legacy Layout": "#2f4aab",
"KiCad Schematic": "#2f4aab",
@@ -369,7 +362,6 @@
"PicoLisp": "#6067af",
"PigLatin": "#fcd7de",
"Pike": "#005390",
"PlantUML": "#fbbd16",
"PogoScript": "#d80074",
"Polar": "#ae81ff",
"Portugol": "#f8bd00",
@@ -387,7 +379,6 @@
"Puppet": "#302B6D",
"PureBasic": "#5a6986",
"PureScript": "#1D222D",
"Pyret": "#ee1e10",
"Python": "#3572A5",
"Python console": "#3572A5",
"Python traceback": "#3572A5",
@@ -540,6 +531,7 @@
"fish": "#4aae47",
"hoon": "#00b171",
"jq": "#c7254e",
"just": "#384d54",
"kvlang": "#1da6e0",
"mIRC Script": "#3d57c3",
"mcfunction": "#E22837",
@@ -69,29 +69,7 @@ exports[`Test Render Wakatime Card should render correctly with compact layout 1
}
@keyframes slideInAnimation {
from {
width: 0;
}
to {
width: calc(100%-100px);
}
}
@keyframes growWidthAnimation {
from {
width: 0;
}
to {
width: 100%;
}
}
.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: #434d58 }
#rect-mask rect{
animation: slideInAnimation 1s ease-in-out forwards;
}
.lang-progress{
animation: growWidthAnimation 0.6s ease-in-out forwards;
}
@@ -249,29 +227,7 @@ exports[`Test Render Wakatime Card should render correctly with compact layout w
}
@keyframes slideInAnimation {
from {
width: 0;
}
to {
width: calc(100%-100px);
}
}
@keyframes growWidthAnimation {
from {
width: 0;
}
to {
width: 100%;
}
}
.lang-name { font: 400 11px 'Segoe UI', Ubuntu, Sans-Serif; fill: #434d58 }
#rect-mask rect{
animation: slideInAnimation 1s ease-in-out forwards;
}
.lang-progress{
animation: growWidthAnimation 0.6s ease-in-out forwards;
}
+3 -3
View File
@@ -15,14 +15,14 @@ const REPO = "curly-fiesta";
const USER = "catelinemnemosyne";
const STATS_DATA = {
name: "Cateline Mnemosyne",
totalPRs: 2,
totalCommits: 8,
totalPRs: 1,
totalCommits: 7,
totalIssues: 1,
totalStars: 1,
contributedTo: 1,
rank: {
level: "A+",
score: 50.88831151384285,
score: 50.893750297869225,
},
};
+3 -3
View File
@@ -216,7 +216,7 @@ describe("Test renderTopLanguages", () => {
);
expect(queryAllByTestId(document.body, "lang-progress")[0]).toHaveAttribute(
"width",
"100",
"120",
);
expect(queryAllByTestId(document.body, "lang-name")[1]).toHaveTextContent(
@@ -224,7 +224,7 @@ describe("Test renderTopLanguages", () => {
);
expect(queryAllByTestId(document.body, "lang-progress")[1]).toHaveAttribute(
"width",
"100",
"120",
);
expect(queryAllByTestId(document.body, "lang-name")[2]).toHaveTextContent(
@@ -232,7 +232,7 @@ describe("Test renderTopLanguages", () => {
);
expect(queryAllByTestId(document.body, "lang-progress")[2]).toHaveAttribute(
"width",
"50",
"60",
);
});
-35
View File
@@ -18,27 +18,6 @@ export const themes = {
text_color: "417E87",
bg_color: "ffffff00",
},
shadow_red: {
title_color: "9A0000",
text_color: "444",
icon_color: "4F0000",
border_color: "4F0000",
bg_color: "ffffff00",
},
shadow_green: {
title_color: "007A00",
text_color: "444",
icon_color: "003D00",
border_color: "003D00",
bg_color: "ffffff00",
},
shadow_blue: {
title_color: "00779A",
text_color: "444",
icon_color: "004450",
border_color: "004490",
bg_color: "ffffff00",
},
dark: {
title_color: "fff",
icon_color: "79ff97",
@@ -395,13 +374,6 @@ export const themes = {
border_color: "170F0C",
bg_color: "170F0C",
},
one_dark_pro: {
title_color: "61AFEF",
text_color: "E5C06E",
icon_color: "C678DD",
border_color: "3B4048",
bg_color: "23272E",
},
rose: {
title_color: "8d192b",
text_color: "862931",
@@ -409,13 +381,6 @@ export const themes = {
border_color: "e9d8d4",
bg_color: "e9d8d4",
},
holi_theme: {
title_color: "5FABEE",
text_color: "D6E7FF",
icon_color: "5FABEE",
border_color: "85A4C0",
bg_color: "030314",
},
};
export default themes;