fumadocs-core
Version:
The library for building a documentation website in any React.js framework
43 lines (41 loc) • 968 B
JavaScript
// src/content/github.ts
async function getGithubLastEdit({
repo,
token,
owner,
path,
sha,
options = {},
params: customParams = {}
}) {
const headers = new Headers(options.headers);
const params = new URLSearchParams();
params.set("path", path);
params.set("page", "1");
params.set("per_page", "1");
if (sha) params.set("sha", sha);
for (const [key, value] of Object.entries(customParams)) {
params.set(key, value);
}
if (token) {
headers.append("authorization", token);
}
const res = await fetch(
`https://api.github.com/repos/${owner}/${repo}/commits?${params.toString()}`,
{
cache: "force-cache",
...options,
headers
}
);
if (!res.ok)
throw new Error(
`Failed to fetch last edit time from Git ${await res.text()}`
);
const data = await res.json();
if (data.length === 0) return null;
return new Date(data[0].commit.committer.date);
}
export {
getGithubLastEdit
};