Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/components/overrides/LastUpdated.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import { REPO, getCommitInfo } from "../../utils/git";
import { Image } from "astro:assets";

const { lang, lastUpdated } = Astro.locals.starlightRoute;
const filePath = Astro.locals.starlightRoute.entry.filePath;
Expand All @@ -21,7 +22,20 @@ const info = await getCommitInfo(filePath);
</span>{" "}
{info && (
<span class="nowrap">
by <a href={info.committer.href}>{info.committer.name}</a>
by{" "}
<a href={info.committer.href}>
{info.committer.avatar && (
<Image
src={info.committer.avatar}
alt={info.committer.name}
width="18"
height="18"
loading="lazy"
style="vertical-align: middle; border-radius: 50%; margin-left: 1px; margin-right: 4px;"
/>
)}
{info.committer.name}
</a>{" "}
in <a href={`https://github.com/${REPO}/commit/${info.hash}`}>{info.hash.substring(0, 7)}</a>
</span>
)}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { execSync } from "child_process";
export interface CommitterInfo {
name: string;
href: string;
avatar: string;
}

export interface CommitInfo {
Expand Down Expand Up @@ -41,12 +42,13 @@ export const getCommitInfo = async (filePath: string): Promise<CommitInfo | null
return { hash, committer: cached };
}

const info: CommitterInfo = { name, href: `mailto:${email}` };
const info: CommitterInfo = { name, href: `mailto:${email}`, avatar: "" };

const res = await fetch(`https://api.github.com/repos/${REPO}/commits/${hash}`, GITHUB_OPTIONS);
if (res.ok) {
const commit = await res.json();
info.href = commit.author.html_url;
info.avatar = commit.author.avatar_url;
}

cache.set(email, info);
Expand Down