mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-16 01:01:38 +00:00
add static generate gist page
This commit is contained in:
@ -30,7 +30,7 @@ const nextConfig = {
|
|||||||
? { allowFutureImage: true, unoptimized: true }
|
? { allowFutureImage: true, unoptimized: true }
|
||||||
: { allowFutureImage: true },
|
: { allowFutureImage: true },
|
||||||
},
|
},
|
||||||
assetPrefix: isExport ? './' : undefined,
|
// assetPrefix: isExport ? './' : undefined,
|
||||||
// images:
|
// images:
|
||||||
// process.env.NEXT_BUILD === 'export'
|
// process.env.NEXT_BUILD === 'export'
|
||||||
// ? {
|
// ? {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import Anchor from 'components/mdx/Anchor';
|
import Anchor from 'components/mdx/Anchor';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||||
import { getSignalGist, SingalGist } from 'lib/fetcher';
|
import { getGists, getSignalGist, SingalGist } from 'lib/fetcher';
|
||||||
import { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next';
|
import { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next';
|
||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import avatar from 'public/images/img/avatar.svg';
|
import avatar from 'public/images/img/avatar.svg';
|
||||||
|
import { ParsedUrlQuery } from 'querystring';
|
||||||
import { ReactElement } from 'react';
|
import { ReactElement } from 'react';
|
||||||
|
|
||||||
const MainLayout = dynamic(() => import('layouts/MainLayout'));
|
const MainLayout = dynamic(() => import('layouts/MainLayout'));
|
||||||
@ -58,8 +59,23 @@ const Gist = ({ gist }: InferGetStaticPropsType<typeof getStaticProps>) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getStaticPaths: GetStaticPaths = async () => {
|
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 = 1; i <= last; i++) {
|
||||||
|
const result = await getGists(i);
|
||||||
|
paths.push(...(result?.gists.map((g) => ({ params: { id: g.id } })) ?? []));
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
paths: [],
|
paths,
|
||||||
fallback: 'blocking',
|
fallback: 'blocking',
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -73,19 +89,24 @@ export const getStaticProps: GetStaticProps<{
|
|||||||
notFound: true,
|
notFound: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const gist = await getSignalGist(params.id);
|
try {
|
||||||
if (!gist || !gist.files)
|
const gist = await getSignalGist(params.id);
|
||||||
|
if (!gist || !gist.files)
|
||||||
|
return {
|
||||||
|
notFound: true,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
id: params?.id?.toString(),
|
||||||
|
gist,
|
||||||
|
},
|
||||||
|
revalidate: 600,
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
return {
|
return {
|
||||||
notFound: true,
|
notFound: true,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
return {
|
|
||||||
props: {
|
|
||||||
id: params?.id?.toString(),
|
|
||||||
gist,
|
|
||||||
},
|
|
||||||
revalidate: 600,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Gist.getLayout = function getLayout(page: ReactElement) {
|
Gist.getLayout = function getLayout(page: ReactElement) {
|
||||||
|
Reference in New Issue
Block a user