mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
added static generation for nodes
This commit is contained in:
parent
476ce8ba88
commit
971f7a4984
2 changed files with 30 additions and 7 deletions
|
@ -10,7 +10,7 @@ import { FlowLayout } from '~/layouts/FlowLayout';
|
|||
import { FlowProvider } from '~/utils/providers/FlowProvider';
|
||||
import { getPageTitle } from '~/utils/ssr/getPageTitle';
|
||||
|
||||
export const getStaticProps = async ctx => {
|
||||
export const getStaticProps = async () => {
|
||||
const fallbackData = await getNodeDiff({
|
||||
start: new Date().toISOString(),
|
||||
end: new Date().toISOString(),
|
||||
|
@ -24,7 +24,7 @@ export const getStaticProps = async ctx => {
|
|||
props: {
|
||||
fallbackData,
|
||||
},
|
||||
revalidate: 5 * 60,
|
||||
revalidate: 60 * 60, // every hour
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import React, { FC } from 'react';
|
||||
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { InferGetServerSidePropsType } from 'next';
|
||||
import { InferGetStaticPropsType } from 'next';
|
||||
import { RouteComponentProps } from 'react-router';
|
||||
|
||||
import { apiGetNode } from '~/api/node';
|
||||
import { apiGetNode, getNodeDiff } from '~/api/node';
|
||||
import { NodeHeadMetadata } from '~/components/node/NodeHeadMetadata';
|
||||
import { useNodeComments } from '~/hooks/comments/useNodeComments';
|
||||
import { useScrollToTop } from '~/hooks/dom/useScrollToTop';
|
||||
|
@ -18,8 +18,31 @@ import { CommentContextProvider } from '~/utils/context/CommentContextProvider';
|
|||
import { NodeContextProvider } from '~/utils/context/NodeContextProvider';
|
||||
import { TagsContextProvider } from '~/utils/context/TagsContextProvider';
|
||||
import { NodeRelatedProvider } from '~/utils/providers/NodeRelatedProvider';
|
||||
import { uniqBy } from '~/utils/ramda';
|
||||
|
||||
export const getServerSideProps = async context => {
|
||||
export const getStaticPaths = async () => {
|
||||
const recent = await getNodeDiff({
|
||||
with_heroes: false,
|
||||
with_recent: true,
|
||||
with_updated: true,
|
||||
with_valid: false,
|
||||
});
|
||||
|
||||
const recentIDs = uniqBy(it => it.id, [
|
||||
...(recent.after || []),
|
||||
...(recent.before || []),
|
||||
...(recent.recent || []),
|
||||
])
|
||||
.filter(it => it.id)
|
||||
.map(it => it.id!.toString());
|
||||
|
||||
return {
|
||||
paths: recentIDs.map(id => ({ params: { id } })),
|
||||
fallback: 'blocking',
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticProps = async context => {
|
||||
if (!context.params?.id) {
|
||||
return { props: {} };
|
||||
}
|
||||
|
@ -39,11 +62,11 @@ export const getServerSideProps = async context => {
|
|||
last_seen: fallbackData.last_seen ?? null,
|
||||
},
|
||||
},
|
||||
revalidate: 7 * 86400, // every week
|
||||
};
|
||||
};
|
||||
|
||||
type Props = RouteComponentProps<{ id: string }> &
|
||||
InferGetServerSidePropsType<typeof getServerSideProps>;
|
||||
type Props = RouteComponentProps<{ id: string }> & InferGetStaticPropsType<typeof getStaticProps>;
|
||||
|
||||
const NodePage: FC<Props> = observer(props => {
|
||||
const id = useNodePageParams();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue