oxen-website/pages/index.tsx

51 lines
1.1 KiB
TypeScript

import { GetStaticProps, GetStaticPropsContext } from 'next';
import { IPost } from '../types/cms';
import { CMS } from '../constants';
import { CmsApi } from '../services/cms';
import generateRSSFeed from '../utils/rss';
import { HomeHero } from '../components/HomeHero';
import { HomeHeroBubble } from '../components/HomeHeroBubble';
export default function Index() {
return (
<>
{/* Only visible when no pages are open */}
<HomeHero />
<HomeHeroBubble />
</>
);
}
export const getStaticProps: GetStaticProps = async (
context: GetStaticPropsContext,
) => {
if (process.env.NEXT_PUBLIC_SITE_ENV !== 'development') {
const cms = new CmsApi();
const posts: IPost[] = [];
let page = 1;
let foundAllPosts = false;
// Contentful only allows 100 at a time
while (!foundAllPosts) {
const { entries: _posts } = await cms.fetchBlogEntries(100, page);
if (_posts.length === 0) {
foundAllPosts = true;
continue;
}
posts.push(..._posts);
page++;
}
generateRSSFeed(posts);
}
return {
props: {},
revalidate: CMS.CONTENT_REVALIDATE_RATE,
};
};