Add asset prefix on export

add gists proxy url

add static generate gist page

format
This commit is contained in:
DefectingCat
2022-09-01 18:00:54 +08:00
parent 0d56c162d4
commit bcf2b540d3
5 changed files with 42 additions and 22 deletions

View File

@ -2,10 +2,10 @@ 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 octokit = new Octokit({
auth: password,
// @TODO reverse proxy
baseUrl: 'http://api.github.com',
baseUrl: host,
});
const linkMatch = /<(.*?)>/;

View File

@ -18,6 +18,7 @@
/**
* @type {import('next').NextConfig}
*/
const isExport = process.env.NEXT_BUILD === 'export';
const nextConfig = {
/* config options here */
reactStrictMode: true,
@ -25,11 +26,11 @@ const nextConfig = {
experimental: {
// runtime: 'nodejs',
// outputStandalone: true,
images:
process.env.NEXT_BUILD === 'export'
? { allowFutureImage: true, unoptimized: true }
: { allowFutureImage: true },
images: isExport
? { allowFutureImage: true, unoptimized: true }
: { allowFutureImage: true },
},
// assetPrefix: isExport ? './' : undefined,
// images:
// process.env.NEXT_BUILD === 'export'
// ? {

View File

@ -6,8 +6,7 @@
"dev": "next dev",
"build": "next build && yarn build:search",
"build:export": "cross-env NEXT_BUILD=export next build && cross-env NEXT_BUILD=export next export",
"build:search": "node scripts/build-search.mjs",
"build:search-g": "node scripts/build-search.mjs -g",
"build:search": "node scripts/build-search.mjs -g",
"start": "next start",
"lint": "next lint",
"test": "jest --watch",

View File

@ -1,12 +1,13 @@
import Anchor from 'components/mdx/Anchor';
import dayjs from 'dayjs';
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 dynamic from 'next/dynamic';
import Image from 'next/image';
import Link from 'next/link';
import avatar from 'public/images/img/avatar.svg';
import { ParsedUrlQuery } from 'querystring';
import { ReactElement } from 'react';
const MainLayout = dynamic(() => import('layouts/MainLayout'));
@ -58,8 +59,22 @@ const Gist = ({ gist }: InferGetStaticPropsType<typeof getStaticProps>) => {
};
export const getStaticPaths: GetStaticPaths = async () => {
const result = await getGists();
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 {
paths: [],
paths,
fallback: 'blocking',
};
};
@ -73,19 +88,24 @@ export const getStaticProps: GetStaticProps<{
notFound: true,
};
const gist = await getSignalGist(params.id);
if (!gist || !gist.files)
try {
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 {
notFound: true,
};
return {
props: {
id: params?.id?.toString(),
gist,
},
revalidate: 600,
};
}
};
Gist.getLayout = function getLayout(page: ReactElement) {

View File

@ -9,10 +9,10 @@ import { Octokit } from 'octokit';
*/
async function getGists(page, perPage) {
const password = process.env.NEXT_PUBLIC_GITHUB_API;
const host = process.env.NEXT_PUBLIC_GISTS_HOST ?? 'http://api.github.com';
const octokit = new Octokit({
auth: password,
// @TODO reverse proxy
baseUrl: 'http://api.github.com',
baseUrl: host,
});
return await octokit.rest.gists.list({
page,