upstream #1
@ -4,7 +4,7 @@ import 'katex/dist/katex.css'
|
|||||||
import PageTitle from '@/components/PageTitle'
|
import PageTitle from '@/components/PageTitle'
|
||||||
import { components } from '@/components/MDXComponents'
|
import { components } from '@/components/MDXComponents'
|
||||||
import { MDXLayoutRenderer } from 'pliny/mdx-components'
|
import { MDXLayoutRenderer } from 'pliny/mdx-components'
|
||||||
import { sortPosts, coreContent } from 'pliny/utils/contentlayer'
|
import { sortPosts, coreContent, allCoreContent } from 'pliny/utils/contentlayer'
|
||||||
import { allBlogs, allAuthors } from 'contentlayer/generated'
|
import { allBlogs, allAuthors } from 'contentlayer/generated'
|
||||||
import type { Authors, Blog } from 'contentlayer/generated'
|
import type { Authors, Blog } from 'contentlayer/generated'
|
||||||
import PostSimple from '@/layouts/PostSimple'
|
import PostSimple from '@/layouts/PostSimple'
|
||||||
@ -13,7 +13,6 @@ import PostBanner from '@/layouts/PostBanner'
|
|||||||
import { Metadata } from 'next'
|
import { Metadata } from 'next'
|
||||||
import siteMetadata from '@/data/siteMetadata'
|
import siteMetadata from '@/data/siteMetadata'
|
||||||
|
|
||||||
const isProduction = process.env.NODE_ENV === 'production'
|
|
||||||
const defaultLayout = 'PostLayout'
|
const defaultLayout = 'PostLayout'
|
||||||
const layouts = {
|
const layouts = {
|
||||||
PostSimple,
|
PostSimple,
|
||||||
@ -82,11 +81,25 @@ export const generateStaticParams = async () => {
|
|||||||
|
|
||||||
export default async function Page({ params }: { params: { slug: string[] } }) {
|
export default async function Page({ params }: { params: { slug: string[] } }) {
|
||||||
const slug = decodeURI(params.slug.join('/'))
|
const slug = decodeURI(params.slug.join('/'))
|
||||||
const sortedPosts = sortPosts(allBlogs) as Blog[]
|
// Filter out drafts in production
|
||||||
const postIndex = sortedPosts.findIndex((p) => p.slug === slug)
|
const sortedCoreContents = allCoreContent(sortPosts(allBlogs))
|
||||||
const prev = coreContent(sortedPosts[postIndex + 1])
|
const postIndex = sortedCoreContents.findIndex((p) => p.slug === slug)
|
||||||
const next = coreContent(sortedPosts[postIndex - 1])
|
if (postIndex === -1) {
|
||||||
const post = sortedPosts.find((p) => p.slug === slug) as Blog
|
return (
|
||||||
|
<div className="mt-24 text-center">
|
||||||
|
<PageTitle>
|
||||||
|
Under Construction{' '}
|
||||||
|
<span role="img" aria-label="roadwork sign">
|
||||||
|
🚧
|
||||||
|
</span>
|
||||||
|
</PageTitle>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const prev = sortedCoreContents[postIndex + 1]
|
||||||
|
const next = sortedCoreContents[postIndex - 1]
|
||||||
|
const post = allBlogs.find((p) => p.slug === slug) as Blog
|
||||||
const authorList = post?.authors || ['default']
|
const authorList = post?.authors || ['default']
|
||||||
const authorDetails = authorList.map((author) => {
|
const authorDetails = authorList.map((author) => {
|
||||||
const authorResults = allAuthors.find((p) => p.slug === author)
|
const authorResults = allAuthors.find((p) => p.slug === author)
|
||||||
@ -105,26 +118,13 @@ export default async function Page({ params }: { params: { slug: string[] } }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isProduction && post && 'draft' in post && post.draft === true ? (
|
<script
|
||||||
<div className="mt-24 text-center">
|
type="application/ld+json"
|
||||||
<PageTitle>
|
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
|
||||||
Under Construction{' '}
|
/>
|
||||||
<span role="img" aria-label="roadwork sign">
|
<Layout content={mainContent} authorDetails={authorDetails} next={next} prev={prev}>
|
||||||
🚧
|
<MDXLayoutRenderer code={post.body.code} components={components} toc={post.toc} />
|
||||||
</span>
|
</Layout>
|
||||||
</PageTitle>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<script
|
|
||||||
type="application/ld+json"
|
|
||||||
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
|
|
||||||
/>
|
|
||||||
<Layout content={mainContent} authorDetails={authorDetails} next={next} prev={prev}>
|
|
||||||
<MDXLayoutRenderer code={post.body.code} components={components} toc={post.toc} />
|
|
||||||
</Layout>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user