Merge pull request #69 from DefectingCat/dev

Fix gists page generate error
This commit is contained in:
Defectink
2023-02-07 11:54:22 +08:00
committed by GitHub
3 changed files with 33 additions and 31 deletions

View File

@ -1,15 +1,7 @@
import LinkAnchor from 'components/mdx/link-anchor';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import MainLayout from 'layouts/common/main-layout';
import { getSignalGist, SingalGist } from 'lib/fetcher';
import { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next';
import dynamic from 'next/dynamic';
import Image from 'next/image';
import Link from 'next/link';
import avatar from 'public/images/img/avatar.svg';
import { Fragment, ReactElement, Suspense } from 'react';
import { useRouter } from 'next/router';
import { Suspense } from 'react';
import clsx from 'clsx';
const GistsCode = dynamic(

View File

@ -2,7 +2,7 @@ import { Octokit } from 'octokit';
import { GistsFile } from 'types';
const password = process.env.NEXT_PUBLIC_GITHUB_API;
const host = process.env.NEXT_PUBLIC_GISTS_HOST ?? 'http://api.github.com';
const host = process.env.NEXT_PUBLIC_GISTS_HOST ?? 'https://api.github.com';
const octokit = new Octokit({
auth: password,
baseUrl: host,
@ -76,7 +76,11 @@ export const getGists = async (page = 1, perPage = 10) => {
Object.keys(g.files).map(async (f) => {
const url = g.files[f].raw_url;
if (!url) return;
g.files[f].content = await fetch(url).then((res) => res.text());
try {
g.files[f].content = await fetch(url).then((res) => res.text());
} catch (err) {
console.log(err);
}
})
);
})

View File

@ -4,8 +4,8 @@ import MainLayout from 'layouts/common/main-layout';
import { GetGists, getGists, GetUser, getUser } from 'lib/fetcher';
import { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next';
import dynamic from 'next/dynamic';
import { ParsedUrlQuery } from 'querystring';
import { ReactElement, Suspense } from 'react';
import { useRouter } from 'next/router';
const UserInfo = dynamic(() => import('components/gists/user-info'), {
suspense: true,
@ -26,6 +26,12 @@ const Gists = ({
next,
total,
}: InferGetStaticPropsType<typeof getStaticProps>) => {
const router = useRouter();
if (router.isFallback) {
return <>Loading...</>;
}
return (
<>
<main className="max-w-5xl px-4 mx-auto lg:px-0">
@ -55,27 +61,27 @@ const Gists = ({
};
export const getStaticPaths: GetStaticPaths = async () => {
const result = await getGists();
const next = Number(result?.pageSize.next);
const last = Number(result?.pageSize.last);
const paths: (
| string
| {
params: ParsedUrlQuery;
locale?: string | undefined;
}
)[] = [];
for (let i = next; i <= last; i++) {
paths.push({
params: {
p: i.toString(),
},
});
}
// const result = await getGists();
// const next = Number(result?.pageSize.next);
// const last = Number(result?.pageSize.last);
// const paths: (
// | string
// | {
// params: ParsedUrlQuery;
// locale?: string | undefined;
// }
// )[] = [];
// for (let i = next; i <= last; i++) {
// paths.push({
// params: {
// p: i.toString(),
// },
// });
// }
return {
paths,
fallback: false,
paths: [],
fallback: true,
};
};