3bbb35c323
* small tweaks for those testing on an existing site with missing author or featured image on posts When migrating WordPress or using an exisitng site, sometimes you have published posts wth missing data. The graphql plugin will properly resolve these to null, but some of existing code accessing tries to access the node property on these null values. I've made these properties optional in the pages and also tweaked some of the components along similar lines. * Lint fix Co-authored-by: Luis Alvarez <luis@vercel.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
import Head from 'next/head'
|
|
import Container from '../components/container'
|
|
import MoreStories from '../components/more-stories'
|
|
import HeroPost from '../components/hero-post'
|
|
import Intro from '../components/intro'
|
|
import Layout from '../components/layout'
|
|
import { getAllPostsForHome } from '../lib/api'
|
|
import { CMS_NAME } from '../lib/constants'
|
|
|
|
export default function Index({ allPosts: { edges }, preview }) {
|
|
const heroPost = edges[0]?.node
|
|
const morePosts = edges.slice(1)
|
|
|
|
return (
|
|
<>
|
|
<Layout preview={preview}>
|
|
<Head>
|
|
<title>Next.js Blog Example with {CMS_NAME}</title>
|
|
</Head>
|
|
<Container>
|
|
<Intro />
|
|
{heroPost && (
|
|
<HeroPost
|
|
title={heroPost.title}
|
|
coverImage={heroPost.featuredImage?.node}
|
|
date={heroPost.date}
|
|
author={heroPost.author?.node}
|
|
slug={heroPost.slug}
|
|
excerpt={heroPost.excerpt}
|
|
/>
|
|
)}
|
|
{morePosts.length > 0 && <MoreStories posts={morePosts} />}
|
|
</Container>
|
|
</Layout>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export async function getStaticProps({ preview = false }) {
|
|
const allPosts = await getAllPostsForHome(preview)
|
|
return {
|
|
props: { allPosts, preview },
|
|
}
|
|
}
|