Skip to content

Commit f9fd75d

Browse files
committed
✨ better leaderboard
1 parent 3a47e8e commit f9fd75d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/api-leaderboard/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ const handler = async (req: Request, env: Env) => {
9797
})();
9898

9999
const markdownBlock =
100-
`## ${getScoreSheetScore(scoreSheet)} by ${markdownUser}\n` +
100+
"<details>\n" +
101+
`<summary>${getScoreSheetScore(
102+
scoreSheet
103+
)} by ${markdownUser}</summary>\n` +
104+
"\n" +
101105
"|Combination|Score|Screenshot|\n" +
102106
"|--|--|--|\n" +
103107
categories
@@ -120,7 +124,9 @@ const handler = async (req: Request, env: Env) => {
120124
}"/>` +
121125
" |"
122126
)
123-
.join("\n");
127+
.join("\n") +
128+
"\n" +
129+
"</details>";
124130

125131
const { entries, id } = await getLeaderboard(env);
126132

@@ -130,7 +136,7 @@ const handler = async (req: Request, env: Env) => {
130136
entries.push({ score: getScoreSheetScore(scoreSheet), block: markdownBlock });
131137
entries.sort((a, b) => b.score - a.score);
132138

133-
while (entries.length > 6) entries.pop();
139+
while (entries.length > 10) entries.pop();
134140

135141
await setLeaderboard(env, id, entries);
136142

@@ -171,7 +177,9 @@ const getLeaderboard = async (env: Env) => {
171177
const body = data.repository.issue.body as string;
172178
const id = data.repository.issue.id as string;
173179
const entries = [
174-
...body.matchAll(/## (\d+)[^\n]*\n(\|[^\n]*\|\n?){3,}/g),
180+
...body.matchAll(
181+
/<details>\s*<summary>(\d+).*<\/summary>\n\n(\|.*\|\n){3,}<\/details>/g
182+
),
175183
].map(([block, score]) => ({ block, score: +score }));
176184

177185
return { entries, id };

0 commit comments

Comments
 (0)