Skip to content

Commit

Permalink
Handle 404 when blog post doesn't exist from Sanity. (leerob#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
leerob committed Jun 20, 2022
1 parent 9c202d6 commit eada67c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pages/blog/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export async function getStaticProps({ params, preview = false }) {
const { post } = await getClient(preview).fetch(postQuery, {
slug: params.slug
});

if (!post) {
return { notFound: true };
}

const { html, tweetIDs, readingTime } = await mdxToHtml(post.content);
const tweets = await getTweets(tweetIDs);

Expand Down
5 changes: 5 additions & 0 deletions pages/snippets/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export async function getStaticProps({ params, preview = false }) {
const { snippet } = await getClient(preview).fetch(snippetsQuery, {
slug: params.slug
});

if (!snippet) {
return { notFound: true };
}

const { html } = await mdxToHtml(snippet.content);

return {
Expand Down

0 comments on commit eada67c

Please sign in to comment.