Skip to content

Commit e9ec614

Browse files
authored
feat: include commiter's avatar in LastUpdated footer (#687)
1 parent 0559ed6 commit e9ec614

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/components/overrides/LastUpdated.astro

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
import { REPO, getCommitInfo } from "../../utils/git";
3+
import { Image } from "astro:assets";
34
45
const { lang, lastUpdated } = Astro.locals.starlightRoute;
56
const filePath = Astro.locals.starlightRoute.entry.filePath;
@@ -21,7 +22,20 @@ const info = await getCommitInfo(filePath);
2122
</span>{" "}
2223
{info && (
2324
<span class="nowrap">
24-
by <a href={info.committer.href}>{info.committer.name}</a>
25+
by{" "}
26+
<a href={info.committer.href}>
27+
{info.committer.avatar && (
28+
<Image
29+
src={info.committer.avatar}
30+
alt={info.committer.name}
31+
class="avatar"
32+
width="18"
33+
height="18"
34+
loading="lazy"
35+
/>
36+
)}
37+
{info.committer.name}
38+
</a>{" "}
2539
in <a href={`https://github.com/${REPO}/commit/${info.hash}`}>{info.hash.substring(0, 7)}</a>
2640
</span>
2741
)}
@@ -38,4 +52,11 @@ const info = await getCommitInfo(filePath);
3852
.nowrap {
3953
white-space: nowrap;
4054
}
55+
56+
.avatar {
57+
vertical-align: middle;
58+
border-radius: 50%;
59+
margin-left: 1px;
60+
margin-right: 4px;
61+
}
4162
</style>

src/utils/git.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { execSync } from "child_process";
33
export interface CommitterInfo {
44
name: string;
55
href: string;
6+
avatar?: string;
67
}
78

89
export interface CommitInfo {
@@ -47,6 +48,7 @@ export const getCommitInfo = async (filePath: string): Promise<CommitInfo | null
4748
if (res.ok) {
4849
const commit = await res.json();
4950
info.href = commit.author.html_url;
51+
info.avatar = commit.author.avatar_url;
5052
}
5153

5254
cache.set(email, info);

0 commit comments

Comments
 (0)