-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(starters): Improve null checking & update to best practices #26918
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please! Thanks for doing this Lennart.
Gatsby Cloud Build Reportgatsby 🎉 Your build was successful! See the Deploy preview here. Build Details🕐 Build time: 19m |
Co-authored-by: Matt Kane <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
previous, | ||
next, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check shouldn't be needed, because if the array is empty, the forEach never happens anyway. However, what might be needed is a null check on allMarkdownRemark
. Does that exist if there's no markdown? Shame there's no optional chaining in gatsby-node!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to make it more explicit as I myself can't always remember that e.g. forEach
would behave this way
|
||
// Also explicitly define the Markdown frontmatter | ||
// This way the "MarkdownRemark" queries will return `null` even when no | ||
// blog posts are stored inside "content/blog" instead of returning an error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, well that answers my question. Does it need a null check or does it have an empty nodes
array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The markdownRemark
query returns null
<Layout location={location} title={siteTitle}> | ||
<SEO title="All posts" /> | ||
<Bio /> | ||
<p>No blog posts found. Add markdown posts to "content/blog" (or the directory you specified for the "gatsby-source-filesystem" plugin in gatsby-config.js).</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big fan of this approach. Nice work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this so much, thank you for tackling this! Less friction, fewer papercuts, easier learning by doing 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again, great work on this.
<3 |
<a href={`https://twitter.com/${social?.twitter || ``}`}> | ||
You should follow them on Twitter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think, if there is no twitter name is set, then this a
tag shot not printed?
…byjs#26918) Co-authored-by: Matt Kane <[email protected]>
Description
In order to reduce friction when people modify the
default
andblog
starters I improved those two a bit. Both with newer best practices but also safe-guarding againstnull
by using optional chaining. Furthermore a bit of schema customization forblog
was added.edges { node }
tonodes
NOT FOUND
to something better for screen readersNotes
In theory we could also define the default values for e.g.
siteMetadata
items in the schema customization but I think JS code is more discover-able and easier to understand.