Fix caching to prevent build-time rendering
This commit is contained in:
parent
05bd6822db
commit
a3e2f442a0
1 changed files with 7 additions and 5 deletions
|
@ -21,7 +21,7 @@ const calculateAge = (birthdate: Date): number => {
|
|||
return age;
|
||||
};
|
||||
|
||||
const getRepos = async (username: string) => {
|
||||
const getRepos = async (username: string, options: RequestInit = {}) => {
|
||||
let repos: Repository[] = [];
|
||||
let page = 1;
|
||||
let hasNextPage = true;
|
||||
|
@ -31,6 +31,7 @@ const getRepos = async (username: string) => {
|
|||
headers: {
|
||||
Accept: 'application/vnd.github+json',
|
||||
},
|
||||
...options,
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
|
@ -46,11 +47,12 @@ const getRepos = async (username: string) => {
|
|||
return repos;
|
||||
};
|
||||
|
||||
const getLanguages = async (repo: Repository) => {
|
||||
const getLanguages = async (repo: Repository, options: RequestInit = {}) => {
|
||||
const response = await fetch(repo.languages_url, {
|
||||
headers: {
|
||||
Accept: 'application/vnd.github+json',
|
||||
},
|
||||
...options,
|
||||
});
|
||||
return await response.json();
|
||||
};
|
||||
|
@ -59,7 +61,7 @@ const accumulateLanguages = async (repos: Repository[]) => {
|
|||
const languages: { [key: string]: number } = {};
|
||||
|
||||
for (const repo of repos) {
|
||||
const repoLanguages = await getLanguages(repo);
|
||||
const repoLanguages = await getLanguages(repo, { next: { revalidate: 3600 } });
|
||||
for (const lang in repoLanguages) {
|
||||
languages[lang] = (languages[lang] || 0) + repoLanguages[lang];
|
||||
}
|
||||
|
@ -80,11 +82,11 @@ const accumulateStars = (repos: Repository[]) => {
|
|||
|
||||
export default async function Home() {
|
||||
|
||||
const profileResponse = await fetch('https://api.github.com/users/markusthielker');
|
||||
const profileResponse = await fetch('https://api.github.com/users/markusthielker', { next: { revalidate: 3600 } });
|
||||
const profile = await profileResponse.json() as PublicUser;
|
||||
|
||||
const username = 'markusthielker';
|
||||
const repos = await getRepos(username);
|
||||
const repos = await getRepos(username, { next: { revalidate: 3600 } });
|
||||
const languages = await accumulateLanguages(repos);
|
||||
const stars = accumulateStars(repos);
|
||||
const totalBytes = Object.values(languages).reduce((sum, bytes) => sum + bytes, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue