import { graphql } from "@octokit/graphql"; import { NextSeo } from "next-seo"; import Title from "../components/Title/Title"; import RepoCard from "../components/RepositoryCard/RepositoryCard"; import { ProjectsIcon } from "../components/Icons"; import type { GetStaticProps } from "next"; import { RepoType } from "../types"; const Projects = (props: { repos: RepoType[] }) => ( <> <ProjectsIcon /> Projects
{props.repos.map((repo: RepoType) => (
))}

View more on GitHub...

); export const getStaticProps: GetStaticProps = async () => { // https://docs.github.com/en/graphql/reference/objects#repository const { user } = await graphql( ` query ($username: String!, $sort: String, $limit: Int) { user(login: $username) { repositories( first: $limit isLocked: false isFork: false ownerAffiliations: OWNER privacy: PUBLIC orderBy: { field: $sort, direction: DESC } ) { edges { node { name url description pushedAt stargazerCount forkCount primaryLanguage { name color } } } } } } `, { username: "jakejarvis", limit: 12, sort: "STARGAZERS", headers: { authorization: `token ${process.env.GH_PUBLIC_TOKEN}`, }, } ); const repos: RepoType[] = user.repositories.edges.map(({ node: repo }) => ({ name: repo.name, url: repo.url, description: repo.description, updatedAt: repo.pushedAt, stars: repo.stargazerCount, forks: repo.forkCount, language: repo.primaryLanguage, })); return { props: { repos, }, // fetch updated data and update page every 10 minutes (as needed) // https://nextjs.org/docs/basic-features/data-fetching#incremental-static-regeneration revalidate: 600, }; }; export default Projects;