@@ -4,7 +4,7 @@ import 'katex/dist/katex.css'
44import PageTitle from '@/components/PageTitle'
55import { components } from '@/components/MDXComponents'
66import { MDXLayoutRenderer } from 'pliny/mdx-components'
7- import { sortPosts , coreContent } from 'pliny/utils/contentlayer'
7+ import { sortPosts , coreContent , allCoreContent } from 'pliny/utils/contentlayer'
88import { allBlogs , allAuthors } from 'contentlayer/generated'
99import type { Authors , Blog } from 'contentlayer/generated'
1010import PostSimple from '@/layouts/PostSimple'
@@ -13,7 +13,6 @@ import PostBanner from '@/layouts/PostBanner'
1313import { Metadata } from 'next'
1414import siteMetadata from '@/data/siteMetadata'
1515
16- const isProduction = process . env . NODE_ENV === 'production'
1716const defaultLayout = 'PostLayout'
1817const layouts = {
1918 PostSimple,
@@ -82,11 +81,25 @@ export const generateStaticParams = async () => {
8281
8382export default async function Page ( { params } : { params : { slug : string [ ] } } ) {
8483 const slug = decodeURI ( params . slug . join ( '/' ) )
85- const sortedPosts = sortPosts ( allBlogs ) as Blog [ ]
86- const postIndex = sortedPosts . findIndex ( ( p ) => p . slug === slug )
87- const prev = coreContent ( sortedPosts [ postIndex + 1 ] )
88- const next = coreContent ( sortedPosts [ postIndex - 1 ] )
89- const post = sortedPosts . find ( ( p ) => p . slug === slug ) as Blog
84+ // Filter out drafts in production
85+ const sortedCoreContents = allCoreContent ( sortPosts ( allBlogs ) )
86+ const postIndex = sortedCoreContents . findIndex ( ( p ) => p . slug === slug )
87+ if ( postIndex === - 1 ) {
88+ return (
89+ < div className = "mt-24 text-center" >
90+ < PageTitle >
91+ Under Construction{ ' ' }
92+ < span role = "img" aria-label = "roadwork sign" >
93+ 🚧
94+ </ span >
95+ </ PageTitle >
96+ </ div >
97+ )
98+ }
99+
100+ const prev = sortedCoreContents [ postIndex + 1 ]
101+ const next = sortedCoreContents [ postIndex - 1 ]
102+ const post = allBlogs . find ( ( p ) => p . slug === slug ) as Blog
90103 const authorList = post ?. authors || [ 'default' ]
91104 const authorDetails = authorList . map ( ( author ) => {
92105 const authorResults = allAuthors . find ( ( p ) => p . slug === author )
@@ -105,26 +118,13 @@ export default async function Page({ params }: { params: { slug: string[] } }) {
105118
106119 return (
107120 < >
108- { isProduction && post && 'draft' in post && post . draft === true ? (
109- < div className = "mt-24 text-center" >
110- < PageTitle >
111- Under Construction{ ' ' }
112- < span role = "img" aria-label = "roadwork sign" >
113- 🚧
114- </ span >
115- </ PageTitle >
116- </ div >
117- ) : (
118- < >
119- < script
120- type = "application/ld+json"
121- dangerouslySetInnerHTML = { { __html : JSON . stringify ( jsonLd ) } }
122- />
123- < Layout content = { mainContent } authorDetails = { authorDetails } next = { next } prev = { prev } >
124- < MDXLayoutRenderer code = { post . body . code } components = { components } toc = { post . toc } />
125- </ Layout >
126- </ >
127- ) }
121+ < script
122+ type = "application/ld+json"
123+ dangerouslySetInnerHTML = { { __html : JSON . stringify ( jsonLd ) } }
124+ />
125+ < Layout content = { mainContent } authorDetails = { authorDetails } next = { next } prev = { prev } >
126+ < MDXLayoutRenderer code = { post . body . code } components = { components } toc = { post . toc } />
127+ </ Layout >
128128 </ >
129129 )
130130}
0 commit comments