Skip to content

Commit 8458157

Browse files
committed
feat: preserve scroll position of the left nav
1 parent f80bd31 commit 8458157

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/routes/docs/+middleware.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface GithubProfile {
88
url: string;
99
photo: string;
1010
username: string;
11+
contributions: number;
1112
}
1213

1314
export default ((ctx) => {
@@ -29,13 +30,20 @@ export default ((ctx) => {
2930
}
3031
for (const contribution of await res.json()) {
3132
const author = contribution.author || contribution.commit.author;
32-
contributors[author.login] ??= {
33-
username: author.login,
34-
photo: author.avatar_url,
35-
url: author.html_url,
36-
};
33+
if (contributors[author.login]) {
34+
contributors[author.login].contributions++;
35+
} else {
36+
contributors[author.login] = {
37+
username: author.login,
38+
photo: author.avatar_url,
39+
url: author.html_url,
40+
contributions: 1,
41+
};
42+
}
3743
}
38-
return Object.values(contributors);
44+
return Object.values(contributors).sort(
45+
(a, b) => b.contributions - a.contributions,
46+
);
3947
})
4048
.catch((e) => {
4149
return [];

src/tags/app-menu/app-menu.marko

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ div#site-menu class=styles.menu
1414
a href=value aria-current=($global.url.pathname === value && "true")
1515
${content}
1616

17-
nav class=styles.nav id=styles.siteNav
17+
nav/$nav class=styles.nav id=styles.siteNav
1818
ul
1919
li
2020
strong -- Introduction
@@ -86,3 +86,15 @@ div#site-menu class=styles.menu
8686
,off="HTML"
8787
,on="Concise"
8888
app-switch aria-label="Toggle TS mode" checked:=tsMode off="JS" on="TS"
89+
90+
html-script -- ${`document.getElementById("${styles.siteNav}").scrollTop = +(sessionStorage.getItem("menu-scroll-position") || 0)`}
91+
script --
92+
addEventListener(
93+
"beforeunload",
94+
() => {
95+
sessionStorage.setItem("menu-scroll-position", $nav().scrollTop + "");
96+
},
97+
{
98+
signal: $signal,
99+
},
100+
);

0 commit comments

Comments
 (0)