mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-16 01:01:38 +00:00
Add fallback when no dev
This commit is contained in:
37
app/gists/[page]/page.tsx
Normal file
37
app/gists/[page]/page.tsx
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { getGists } from "lib/fetcher";
|
||||||
|
import { notFound } from "next/navigation";
|
||||||
|
import FileContent from "../file-content";
|
||||||
|
import Pagination from 'components/rua/rua-pagination';
|
||||||
|
|
||||||
|
export const revalidate = 600;
|
||||||
|
|
||||||
|
export default async function Page({params}: {
|
||||||
|
params: {
|
||||||
|
page: string
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
const page = Number(params.page)
|
||||||
|
if (!page) notFound()
|
||||||
|
const gists = await getGists(page);
|
||||||
|
if (!gists) notFound();
|
||||||
|
|
||||||
|
const prev = Number(gists.pageSize.prev);
|
||||||
|
const next = Number(gists.pageSize.next);
|
||||||
|
const total = Number(gists.pageSize.last);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FileContent gists={gists.gists} />
|
||||||
|
<Pagination
|
||||||
|
className="mt-4"
|
||||||
|
hasPrev={!!prev}
|
||||||
|
hasNext={!!next}
|
||||||
|
prevLink={prev === 1 ? `/gists/` : `/gists/${prev}`}
|
||||||
|
nextLink={`/gists/${next}`}
|
||||||
|
current={prev == null ? next - 1 : prev + 1}
|
||||||
|
total={total}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
@ -3,6 +3,8 @@ import { GistsFile } from 'types';
|
|||||||
|
|
||||||
const password = process.env.NEXT_PUBLIC_GITHUB_API;
|
const password = process.env.NEXT_PUBLIC_GITHUB_API;
|
||||||
const host = process.env.NEXT_PUBLIC_GISTS_HOST ?? 'https://api.github.com';
|
const host = process.env.NEXT_PUBLIC_GISTS_HOST ?? 'https://api.github.com';
|
||||||
|
|
||||||
|
if (!password) throw new Error('No GitHub token detected.')
|
||||||
const octokit = new Octokit({
|
const octokit = new Octokit({
|
||||||
auth: password,
|
auth: password,
|
||||||
baseUrl: host,
|
baseUrl: host,
|
||||||
|
Reference in New Issue
Block a user