Added 'most popular repo' section to landing page
continuous-integration/drone/push Build is passing Details

main
Guus van Meerveld 2 years ago
parent ad9ff85a09
commit 45834b4e61
Signed by: Guusvanmeerveld
GPG Key ID: 2BA7D7912771966E

@ -19,6 +19,7 @@
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"spectre.css": "^0.5.9", "spectre.css": "^0.5.9",
"timeago.js": "^4.0.2",
"zod": "^3.20.6" "zod": "^3.20.6"
}, },
"devDependencies": { "devDependencies": {

@ -3,6 +3,8 @@ import Link from "next/link";
import { FC } from "react"; import { FC } from "react";
import z from "zod"; import z from "zod";
import { format as formatTimeAgo } from "timeago.js";
import { RepositoryResponse } from "@models/responses"; import { RepositoryResponse } from "@models/responses";
const BestRepository: FC<{ repository: z.infer<typeof RepositoryResponse> }> = const BestRepository: FC<{ repository: z.infer<typeof RepositoryResponse> }> =
@ -14,7 +16,7 @@ const BestRepository: FC<{ repository: z.infer<typeof RepositoryResponse> }> =
<div className="column col-8 col-md-12 col-mx-auto"> <div className="column col-8 col-md-12 col-mx-auto">
<h3 className="text-secondary">My most popular project:</h3> <h3 className="text-secondary">My most popular project:</h3>
<h1>{repository.full_name}</h1> <h1>{repository.full_name}</h1>
<h3 className="text-secondary">{repository.size} byes</h3>
<h5>{repository.description}</h5> <h5>{repository.description}</h5>
<p className="text-secondary"> <p className="text-secondary">
Written in {repository.language}, has{" "} Written in {repository.language}, has{" "}
@ -34,8 +36,7 @@ const BestRepository: FC<{ repository: z.infer<typeof RepositoryResponse> }> =
</p> </p>
<h5 className="text-secondary"> <h5 className="text-secondary">
Last commit on{" "} Last updated {formatTimeAgo(repository.updated_at, "en_US")}
{new Date(repository.updated_at).toLocaleDateString()}
</h5> </h5>
</div> </div>
</div> </div>

@ -1,6 +1,8 @@
import z from "zod"; import z from "zod";
import { FC } from "react"; import { FC } from "react";
import { format as formatTimeAgo } from "timeago.js";
import Link from "next/link"; import Link from "next/link";
import multipleClassNames from "@utils/multipleClassNames"; import multipleClassNames from "@utils/multipleClassNames";
@ -40,13 +42,14 @@ const FeaturedRepositories: FC<{
{repository.full_name} {repository.full_name}
</div> </div>
<div className="card-subtitle text-gray"> <div className="card-subtitle text-gray">
{repository.size} bytes {(repository.size / 1024).toPrecision(2)} MB - Last
updated {formatTimeAgo(repository.updated_at, "en_US")}
</div> </div>
</div> </div>
<div className="card-body">{repository.description}</div> <div className="card-body">{repository.description}</div>
<div className="card-footer"> <div className="card-footer">
<Link href={repository.html_url}> <Link href={repository.html_url}>
<a className="btn btn-primary">Github</a> <a className="btn btn-primary">Git</a>
</Link> </Link>
{repository.website && ( {repository.website && (

@ -9,6 +9,7 @@ export const RepositoryResponse = z.object({
updated_at: z.string(), updated_at: z.string(),
forks_count: z.number(), forks_count: z.number(),
open_issues_count: z.number(), open_issues_count: z.number(),
stars_count: z.number(),
description: z.string(), description: z.string(),
size: z.number() size: z.number()
}); });

@ -1,3 +1,5 @@
import z from "zod";
import { NextSeo } from "next-seo"; import { NextSeo } from "next-seo";
import { GetStaticProps, InferGetStaticPropsType, NextPage } from "next"; import { GetStaticProps, InferGetStaticPropsType, NextPage } from "next";
@ -7,6 +9,8 @@ import Layout from "@components/Layout";
import FeaturedRepositories from "@components/FeaturedRepositories"; import FeaturedRepositories from "@components/FeaturedRepositories";
import BestRepository from "@components/BestRepository"; import BestRepository from "@components/BestRepository";
import { RepositoryResponse } from "@models/responses";
import { fetchAvailability, fetchRepositories, fetchUser } from "@utils/fetch"; import { fetchAvailability, fetchRepositories, fetchUser } from "@utils/fetch";
import { giteaUsername } from "@utils/config"; import { giteaUsername } from "@utils/config";
@ -17,10 +21,15 @@ export const getStaticProps: GetStaticProps = async () => {
const repositories = await fetchRepositories(user.id); const repositories = await fetchRepositories(user.id);
const bestRepository: z.infer<typeof RepositoryResponse> | undefined =
repositories.reduce((prev, current) =>
prev.stars_count > current.stars_count ? prev : current
);
return { return {
props: { props: {
isAvailable, isAvailable,
user, user,
bestRepository,
repositories repositories
}, },
revalidate: 60 * 5 revalidate: 60 * 5
@ -30,14 +39,14 @@ export const getStaticProps: GetStaticProps = async () => {
const Index: NextPage = ({ const Index: NextPage = ({
repositories, repositories,
user, user,
bestRepository,
isAvailable isAvailable
}: // bestRepository }: InferGetStaticPropsType<typeof getStaticProps>) => (
InferGetStaticPropsType<typeof getStaticProps>) => (
<Layout> <Layout>
<NextSeo title="Home" /> <NextSeo title="Home" />
<User isAvailable={isAvailable} user={user} /> <User isAvailable={isAvailable} user={user} />
<FeaturedRepositories repositories={repositories} /> <FeaturedRepositories repositories={repositories} />
{/* <BestRepository repository={bestRepository} /> */} <BestRepository repository={bestRepository} />
</Layout> </Layout>
); );

@ -40,7 +40,8 @@ export const fetchRepositories = async (
params: { params: {
topic: true, topic: true,
q: "on-portfolio", q: "on-portfolio",
id: giteaUserUid id: giteaUserUid,
limit: 6
} }
} }
); );

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save