Skip to content

Commit de4cefa

Browse files
committed
fix: fix commit stats time frame description #1053
This commit makes sure the last year label is shown when `include_all_commits` or `year` is not provided. See #1053 for more information.
1 parent af6553e commit de4cefa

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/cards/stats-card.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
134134
commits: {
135135
icon: icons.commits,
136136
label: `${i18n.t("statcard.commits")}${
137-
include_all_commits
138-
? ""
139-
: year
140-
? ` (${year})`
141-
: ` (${new Date().getFullYear()})`
137+
include_all_commits ? "" : year ? ` (${year})` : ` (last year)`
142138
}`,
143139
value: totalCommits,
144140
id: "commits",
@@ -188,7 +184,8 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
188184
index,
189185
showIcons: show_icons,
190186
shiftValuePos:
191-
(!include_all_commits ? 50 : 35) + (isLongLocale ? 50 : 0),
187+
(include_all_commits ? 35 : year ? 50 : 80.22) +
188+
(isLongLocale ? 50 : 0),
192189
bold: text_bold,
193190
}),
194191
);
@@ -296,7 +293,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
296293
.map((key) => {
297294
if (key === "commits") {
298295
return `${i18n.t("statcard.commits")} ${
299-
include_all_commits ? "" : `in ${new Date().getFullYear()}`
296+
include_all_commits ? "" : year ? ` (${year})` : ` (last year)`
300297
} : ${totalStars}`;
301298
}
302299
return `${STATS[key].label}: ${STATS[key].value}`;

tests/renderStatsCard.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe("Test renderStatsCard", () => {
296296
document.querySelector(
297297
'g[transform="translate(0, 25)"]>.stagger>.stat.bold',
298298
).textContent,
299-
).toMatchInlineSnapshot(`"累计提交数(commit) (2022):"`);
299+
).toMatchInlineSnapshot(`"累计提交数(commit) (last year):"`);
300300
expect(
301301
document.querySelector(
302302
'g[transform="translate(0, 50)"]>.stagger>.stat.bold',

0 commit comments

Comments
 (0)