Unverified Commit b41f9baa authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Fix up CMS examples (#12840)

parent f1423518
...@@ -59,8 +59,8 @@ export async function getStaticProps({ params, preview = false }) { ...@@ -59,8 +59,8 @@ export async function getStaticProps({ params, preview = false }) {
return { return {
props: { props: {
preview, preview,
post: data?.post, post: data?.post ?? null,
morePosts: data?.morePosts, morePosts: data?.morePosts ?? null,
}, },
} }
} }
...@@ -68,7 +68,7 @@ export async function getStaticProps({ params, preview = false }) { ...@@ -68,7 +68,7 @@ export async function getStaticProps({ params, preview = false }) {
export async function getStaticPaths() { export async function getStaticPaths() {
const allPosts = await getAllPostsWithSlug() const allPosts = await getAllPostsWithSlug()
return { return {
paths: allPosts?.map(({ slug }) => `/posts/${slug}`) || [], paths: allPosts?.map(({ slug }) => `/posts/${slug}`) ?? [],
fallback: true, fallback: true,
} }
} }
...@@ -35,7 +35,7 @@ export default function Index({ allPosts }) { ...@@ -35,7 +35,7 @@ export default function Index({ allPosts }) {
) )
} }
export async function getStaticProps({ preview }) { export async function getStaticProps({ preview = false }) {
const allPosts = (await getAllPostsForHome(preview)) || [] const allPosts = (await getAllPostsForHome(preview)) || []
return { return {
props: { allPosts }, props: { allPosts },
......
...@@ -50,7 +50,7 @@ export default function Post({ post, morePosts, preview }) { ...@@ -50,7 +50,7 @@ export default function Post({ post, morePosts, preview }) {
) )
} }
export async function getStaticProps({ params, preview = null }) { export async function getStaticProps({ params, preview = false }) {
const data = await getPostAndMorePosts(params.slug, preview) const data = await getPostAndMorePosts(params.slug, preview)
const content = await markdownToHtml(data?.post?.content || '') const content = await markdownToHtml(data?.post?.content || '')
...@@ -61,7 +61,7 @@ export async function getStaticProps({ params, preview = null }) { ...@@ -61,7 +61,7 @@ export async function getStaticProps({ params, preview = null }) {
...data?.post, ...data?.post,
content, content,
}, },
morePosts: data?.morePosts, morePosts: data?.morePosts ?? [],
}, },
} }
} }
......
...@@ -35,7 +35,7 @@ export default function Index({ preview, allPosts }) { ...@@ -35,7 +35,7 @@ export default function Index({ preview, allPosts }) {
) )
} }
export async function getStaticProps({ preview, previewData }) { export async function getStaticProps({ preview = false, previewData }) {
const allPosts = await getAllPostsForHome(previewData) const allPosts = await getAllPostsForHome(previewData)
return { return {
props: { preview, allPosts }, props: { preview, allPosts },
......
...@@ -52,14 +52,14 @@ export default function Post({ post, morePosts, preview }) { ...@@ -52,14 +52,14 @@ export default function Post({ post, morePosts, preview }) {
) )
} }
export async function getStaticProps({ params, preview, previewData }) { export async function getStaticProps({ params, preview = false, previewData }) {
const data = await getPostAndMorePosts(params.slug, previewData) const data = await getPostAndMorePosts(params.slug, previewData)
return { return {
props: { props: {
preview, preview,
post: data?.post, post: data?.post ?? null,
morePosts: data?.morePosts, morePosts: data?.morePosts ?? [],
}, },
} }
} }
......
...@@ -54,8 +54,8 @@ export async function getStaticProps({ params, preview = false }) { ...@@ -54,8 +54,8 @@ export async function getStaticProps({ params, preview = false }) {
return { return {
props: { props: {
preview, preview,
post: data.post || null, post: data?.post || null,
morePosts: data.morePosts || null, morePosts: data?.morePosts || null,
}, },
} }
} }
......
...@@ -35,7 +35,7 @@ export default function Index({ allPosts, preview }) { ...@@ -35,7 +35,7 @@ export default function Index({ allPosts, preview }) {
) )
} }
export async function getStaticProps({ preview = null }) { export async function getStaticProps({ preview = false }) {
const allPosts = await getAllPostsForHome(preview) const allPosts = await getAllPostsForHome(preview)
return { return {
props: { allPosts, preview }, props: { allPosts, preview },
......
...@@ -59,7 +59,7 @@ export default function Post({ post, morePosts, preview }) { ...@@ -59,7 +59,7 @@ export default function Post({ post, morePosts, preview }) {
) )
} }
export async function getStaticProps({ params, preview = null }) { export async function getStaticProps({ params, preview = false }) {
const data = await getPostAndMorePosts(params.slug, preview) const data = await getPostAndMorePosts(params.slug, preview)
const content = await markdownToHtml( const content = await markdownToHtml(
(data?.post?.items || [])[0]?.content || '' (data?.post?.items || [])[0]?.content || ''
...@@ -72,7 +72,7 @@ export async function getStaticProps({ params, preview = null }) { ...@@ -72,7 +72,7 @@ export async function getStaticProps({ params, preview = null }) {
...(data?.post?.items || [])[0], ...(data?.post?.items || [])[0],
content, content,
}, },
morePosts: data?.morePosts.items, morePosts: data?.morePosts.items ?? [],
}, },
} }
} }
......
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