Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 0acf611

Browse files
committed
1.8
1 parent d6f856d commit 0acf611

3 files changed

Lines changed: 49 additions & 8 deletions

File tree

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ module.exports = {
22
token: process.env.CODE_STATISTIC, // GitHub Access Token (Minimum permissions). Increase QPS of GitHub APIs.
33
expiration: 3600, // expiration second
44
requires: ["*"], // CODE STATISTIC can only be parsed for allowed users. ( * indicates that all users are allowed )
5-
port: 80, // server port
5+
port: 8000, // server port
66
}

stats.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ function langHandler(langs) {
601601
langs = {...langs}; // 这里有一个很神奇的关于指针的Bug的回忆
602602
// (缓存与操作的对象指向一个Array, 导致了奇妙的事情发生, 有意者可以亲自拉下代码复刻这一[特性])
603603
const val_arr = sort(Object.values(langs)).reverse();
604-
const total = val_arr.reduce((before, after) => before + after);
604+
const total = val_arr.length ? val_arr.reduce((before, after) => before + after) : 0;
605605
for (let k in langs) {
606606
langs[langs[k]] = k;
607607
delete langs[k];
@@ -622,14 +622,19 @@ function langHandler(langs) {
622622
}
623623
async function getAccount(username, query={}) {
624624
const response = await cache.requestWithCache(`/users/${username}`);
625+
const repos = Object.values(await cache.requestWithCache(`/users/${username}/repos`)).filter(repo => !repo.fork);
625626
return {
626627
dark : query['theme'] === 'dark',
628+
locs: response['location'],
629+
stars: repos.map(repo => repo['stargazers_count']).reduce((a, b) => a + b),
630+
forks: repos.map(repo => repo['forks_count']).reduce((a, b) => a + b),
631+
issues: repos.map(repo => repo['open_issues_count']).reduce((a, b) => a + b),
632+
watchers: repos.map(repo => repo['watchers_count']).reduce((a, b) => a + b),
627633
username: username,
628634
followers: decConvert(response['followers']),
629635
repos: response['public_repos'],
630636
langs: await langStatistics(
631-
Object.values(await cache.requestWithCache(`/users/${username}/repos`)
632-
).map(async (resp) => {
637+
repos.map(async (resp) => {
633638
return await getLanguage(username, resp['name']);
634639
})),
635640
};
@@ -653,6 +658,6 @@ async function getRepository(username, repo, query={}) {
653658
}
654659

655660
module.exports = {
656-
getAccount: getAccount,
657-
getRepository: getRepository,
661+
getAccount,
662+
getRepository,
658663
}

views/user.ejs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% const left = Math.ceil(langs.length / 2); const height = 195 + (left > 4 ? (left - 4) * 20 : 0) %>
1+
<% const left = Math.ceil(langs.length / 2); const height = 215 + (left > 4 ? (left - 4) * 20 : 0) %>
22
<svg width="450" height="195" viewBox="0 0 660 <%- height + 1 %>" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="descId">
33
<title id="titleId"><%- username %>'s Code Stats</title>
44
<desc id="descId">User Code Statistics</desc>
@@ -106,9 +106,45 @@
106106
</svg>
107107
<text class="stat bold" x="192.01" y="12.5" data-testid="forks"><%- repos %></text>
108108
</g>
109+
<g transform="translate(0, 25)">
110+
<g class="stagger" style="animation-delay: 750ms" transform="translate(25, 0)">
111+
<text class="stat bold" y="12.5">Stars Earned:</text>
112+
<svg x="169.01" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="oct-icon">
113+
<path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path>
114+
</svg>
115+
<text class="stat bold" x="192.01" y="12.5" data-testid="forks"><%- stars %></text>
116+
</g>
117+
</g>
118+
<g transform="translate(0, 50)">
119+
<g class="stagger" style="animation-delay: 1050ms" transform="translate(25, 0)">
120+
<text class="stat bold" y="12.5">Forks Earned:</text>
121+
<svg x="169.01" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="oct-icon">
122+
<path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path>
123+
</svg>
124+
<text class="stat bold" x="192.01" y="12.5" data-testid="forks"><%- forks %></text>
125+
</g>
126+
</g>
127+
<g transform="translate(0, 75)">
128+
<g class="stagger" style="animation-delay: 1200ms" transform="translate(25, 0)">
129+
<text class="stat bold" y="12.5">Open Issues:</text>
130+
<svg x="169.01" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="oct-icon">
131+
<path d="M8 9.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3z"></path><path fill-rule="evenodd" d="M8 0a8 8 0 100 16A8 8 0 008 0zM1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0z"></path>
132+
</svg>
133+
<text class="stat bold" x="192.01" y="12.5" data-testid="forks"><%- issues %></text>
134+
</g>
135+
</g>
136+
<g transform="translate(0, 100)">
137+
<g class="stagger" style="animation-delay: 1350ms" transform="translate(25, 0)">
138+
<text class="stat bold" y="12.5">Watchers Total:</text>
139+
<svg x="169.01" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="oct-icon">
140+
<path fill-rule="evenodd" d="M1.679 7.932c.412-.621 1.242-1.75 2.366-2.717C5.175 4.242 6.527 3.5 8 3.5c1.473 0 2.824.742 3.955 1.715 1.124.967 1.954 2.096 2.366 2.717a.119.119 0 010 .136c-.412.621-1.242 1.75-2.366 2.717C10.825 11.758 9.473 12.5 8 12.5c-1.473 0-2.824-.742-3.955-1.715C2.92 9.818 2.09 8.69 1.679 8.068a.119.119 0 010-.136zM8 2c-1.981 0-3.67.992-4.933 2.078C1.797 5.169.88 6.423.43 7.1a1.619 1.619 0 000 1.798c.45.678 1.367 1.932 2.637 3.024C4.329 13.008 6.019 14 8 14c1.981 0 3.67-.992 4.933-2.078 1.27-1.091 2.187-2.345 2.637-3.023a1.619 1.619 0 000-1.798c-.45-.678-1.367-1.932-2.637-3.023C11.671 2.992 9.981 2 8 2zm0 8a2 2 0 100-4 2 2 0 000 4z"></path>
141+
</svg>
142+
<text class="stat bold" x="192.01" y="12.5" data-testid="forks"><%- watchers %></text>
143+
</g>
144+
</g>
109145
</g>
110146
</svg></g>
111-
<line x1="290" y1="40" x2="290" y2="186" stroke="#eeecec"></line>
147+
<line x1="290" y1="40" x2="290" y2="<%- height - 40 %>" stroke="#eeecec"></line>
112148
<g xmlns="http://www.w3.org/2000/svg" transform="translate(300, 55)" data-testid="main-card-progress">
113149

114150
<svg data-testid="lang-items" x="25">

0 commit comments

Comments
 (0)