mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import dayjs from 'dayjs';
|
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
import { GetGists, getGists, GetUser, getUser } from 'lib/fetcher';
|
|
import { GetStaticProps, InferGetStaticPropsType } from 'next';
|
|
import dynamic from 'next/dynamic';
|
|
import { ReactElement } from 'react';
|
|
|
|
const MainLayout = dynamic(() => import('layouts/MainLayout'));
|
|
const UserInfo = dynamic(() => import('components/gists/UserInfo'));
|
|
const FileContent = dynamic(() => import('components/gists/FileContent'));
|
|
|
|
dayjs.extend(relativeTime);
|
|
|
|
const Gists = ({
|
|
gists,
|
|
user,
|
|
}: InferGetStaticPropsType<typeof getStaticProps>) => {
|
|
return (
|
|
<>
|
|
<main className="max-w-5xl px-4 mx-auto lg:px-0">
|
|
<div className="md:flex">
|
|
<UserInfo user={user} />
|
|
<FileContent gists={gists.gists} />
|
|
</div>
|
|
</main>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export const getStaticProps: GetStaticProps<{
|
|
gists: GetGists;
|
|
user: GetUser;
|
|
}> = async () => {
|
|
const result = await getGists();
|
|
if (!result)
|
|
return {
|
|
notFound: true,
|
|
};
|
|
|
|
const user = await getUser();
|
|
|
|
return {
|
|
props: {
|
|
gists: result,
|
|
user,
|
|
},
|
|
revalidate: 600,
|
|
};
|
|
};
|
|
|
|
Gists.getLayout = function getLayout(page: ReactElement) {
|
|
return <MainLayout>{page}</MainLayout>;
|
|
};
|
|
|
|
export default Gists;
|