2021-09-03 16:10:01 +02:00
|
|
|
import { GetStaticProps, GetStaticPropsContext } from 'next';
|
|
|
|
|
|
|
|
import { IPost } from '../types/cms';
|
2021-09-19 03:01:10 +02:00
|
|
|
import { CMS } from '../constants';
|
2021-09-03 16:10:01 +02:00
|
|
|
import { CmsApi } from '../services/cms';
|
|
|
|
import generateRSSFeed from '../utils/rss';
|
|
|
|
|
2021-02-12 04:14:34 +01:00
|
|
|
import { HomeHero } from '../components/HomeHero';
|
|
|
|
import { HomeHeroBubble } from '../components/HomeHeroBubble';
|
2021-01-22 03:43:42 +01:00
|
|
|
|
2021-09-03 16:10:01 +02:00
|
|
|
export default function Index() {
|
2021-01-22 03:43:42 +01:00
|
|
|
return (
|
2021-02-18 04:07:53 +01:00
|
|
|
<>
|
2021-02-12 04:14:34 +01:00
|
|
|
{/* Only visible when no pages are open */}
|
2021-03-19 06:08:13 +01:00
|
|
|
<HomeHero />
|
|
|
|
<HomeHeroBubble />
|
2021-02-18 04:07:53 +01:00
|
|
|
</>
|
2021-01-22 03:43:42 +01:00
|
|
|
);
|
2021-09-03 16:10:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2021-01-22 03:43:42 +01:00
|
|
|
|
2021-09-03 16:10:01 +02:00
|
|
|
if (_posts.length === 0) {
|
|
|
|
foundAllPosts = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
posts.push(..._posts);
|
|
|
|
page++;
|
|
|
|
}
|
|
|
|
|
|
|
|
generateRSSFeed(posts);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {},
|
|
|
|
revalidate: CMS.CONTENT_REVALIDATE_RATE,
|
|
|
|
};
|
|
|
|
};
|