Unverified Commit 3bbb35c3 authored by ospira's avatar ospira Committed by GitHub

small tweaks for those testing on an existing site with missing autho… (#18506)

* 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: 's avatarLuis Alvarez <luis@vercel.com>
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 61981da9
export default function Avatar({ author }) { export default function Avatar({ author }) {
const name = const name = author
author.firstName && author.lastName ? author.firstName && author.lastName
? `${author.firstName} ${author.lastName}` ? `${author.firstName} ${author.lastName}`
: author.name : author.name
: null
return ( return (
<div className="flex items-center"> <>
<img {author && (
src={author.avatar.url} <div className="flex items-center">
className="w-12 h-12 rounded-full mr-4" <img
alt={name} src={author.avatar.url}
/> className="w-12 h-12 rounded-full mr-4"
<div className="text-xl font-bold">{name}</div> alt={name}
</div> />
<div className="text-xl font-bold">{name}</div>
</div>
)}
</>
) )
} }
...@@ -14,7 +14,9 @@ export default function HeroPost({ ...@@ -14,7 +14,9 @@ export default function HeroPost({
return ( return (
<section> <section>
<div className="mb-8 md:mb-16"> <div className="mb-8 md:mb-16">
<CoverImage title={title} coverImage={coverImage} slug={slug} /> {coverImage && (
<CoverImage title={title} coverImage={coverImage} slug={slug} />
)}
</div> </div>
<div className="md:grid md:grid-cols-2 md:col-gap-16 lg:col-gap-8 mb-20 md:mb-28"> <div className="md:grid md:grid-cols-2 md:col-gap-16 lg:col-gap-8 mb-20 md:mb-28">
<div> <div>
......
...@@ -11,9 +11,9 @@ export default function MoreStories({ posts }) { ...@@ -11,9 +11,9 @@ export default function MoreStories({ posts }) {
<PostPreview <PostPreview
key={node.slug} key={node.slug}
title={node.title} title={node.title}
coverImage={node.featuredImage.node} coverImage={node.featuredImage?.node}
date={node.date} date={node.date}
author={node.author.node} author={node.author?.node}
slug={node.slug} slug={node.slug}
excerpt={node.excerpt} excerpt={node.excerpt}
/> />
......
...@@ -22,9 +22,9 @@ export default function Index({ allPosts: { edges }, preview }) { ...@@ -22,9 +22,9 @@ export default function Index({ allPosts: { edges }, preview }) {
{heroPost && ( {heroPost && (
<HeroPost <HeroPost
title={heroPost.title} title={heroPost.title}
coverImage={heroPost.featuredImage.node} coverImage={heroPost.featuredImage?.node}
date={heroPost.date} date={heroPost.date}
author={heroPost.author.node} author={heroPost.author?.node}
slug={heroPost.slug} slug={heroPost.slug}
excerpt={heroPost.excerpt} excerpt={heroPost.excerpt}
/> />
......
...@@ -41,9 +41,9 @@ export default function Post({ post, posts, preview }) { ...@@ -41,9 +41,9 @@ export default function Post({ post, posts, preview }) {
</Head> </Head>
<PostHeader <PostHeader
title={post.title} title={post.title}
coverImage={post.featuredImage.node} coverImage={post.featuredImage?.node}
date={post.date} date={post.date}
author={post.author.node} author={post.author?.node}
categories={post.categories} categories={post.categories}
/> />
<PostBody content={post.content} /> <PostBody content={post.content} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment